Community
Participate
Working Groups
Consider: public class PrivateAccessor { public static <T> T get(Object object, String fieldName) { return getField(object, fieldName); } } In this case 'getField(...)' is indicated with the error "Type mismatch: cannot convert from Object to T PrivateAccessor.java". If the code is changed to: public static <T> T get(Object object, String fieldName) { return (T) getField(object, fieldName); } The '(T) getField(...)' is indicated with the warning "Unnessary cast from Object to T".
Indeed Object is not compatible with the type parameter T. (T could be substituted with String for example). javac has the same behavior.
But then why the warning indicating the unecessary cast? My point was that it should not /both/ be an error in one case and a warning in the other. No?