What area should the variable have?
There are three possibilities.
A) . ... :
interface ItfA { Number propA(); };
interface ItfB { Number propB(); };
class Main {
private <T extends ItfA & ItfB> T getT() {
return null;
}
private <TT extends ItfA & ItfB> void doStuffWithT() {
TT theT = getT();
System.err.println(theT.propA());
System.err.println(theT.propB());
}
}
B) - , .
generic
&:
interface ItfA { Number propA(); };
interface ItfB { Number propB(); };
class Main<T extends ItfA & ItfB> {
T theT;
public void setT(T newT) {
theT = newT;
}
public void doStuffWithT() {
System.err.println(theT.propA());
System.err.println(theT.propB());
}
}
C) - , . generics.
C.1) , , , , .
C.2) , , , ItfA ItfB. , ItfAB. .
C.3) , ? , ?
, :
C.3.a) Object, ItfA ItfB ( ).
C.3.b) , , -, , "T". - , <T extends ItfA & ItfB> ( B.).