I was confused with my code, which includes a generic method that takes no parameters, so what will be the returned generic type of such a method, for example:
static <T> example<T> getObj() {
return new example<T>() {
public T getObject() {
return null;
}
};
}
and this was called through:
example<String> exm = getObj(); // it accepts anything String like in this case or Object and everything
protection example's:
public interface example<T> {
T getObject();
}
My question is: example<String> exmaccepts String, Object and all. So, at what time is the typical return type indicated as String and how?
source
share