I was confused with my code that includes a generic method that takes no parameters, so what will be the return generic type of such a method, eg:
static <T> example<T> getObj() {
return new example<T>() {
public T getObject() {
return null;
}
};
}
and this was called via:
example<String> exm = getObj(); // it accepts anything String like in this case or Object and everything
the interface example's
defination is:
public interface example<T> {
T getObject();
}
My question:example<String> exm
is accepting String, Object and everything. So at what time generic return type is specified as String and how??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…