I need a object who refers to two diffenrent interfaces like this:
interface InterfaceA {
public void a();
}
interface InterfaceB {
public void b();
}
class Test() {
Object <? implements InterfaceA, InterfaceB>; object;
Test() {
object.a();
object.b();
}
}
I know for inheritance there is this way: Class <? extends Main> a
Class <? extends Main> a
and a solution could be a helper class: class Helperclass implements InterfaceA, InterfaceB{}
Thanks for help and reading :)
If you add a generic type parameter to your Test
class, you can require that this type parameter implement both interfaces:
class Test<T extends InterfaceA & InterfaceB> {
T object;
Test() {
object.a();
object.b();
}
}
Of course you should initialize the object
variable before calling methods.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.