This is not about Eclipse or anything else, but about raw types.
Check out this snippet:
public static void main(String[] args) { Object obj = new GenericOptional<>(Boolean.TRUE); GenericOptional go = (GenericOptional) obj; Optional os = go.getOptionalString(); }
Here you create a raw instance of GenericOptional , which means that the type parameter information will be completely disabled. So, creating an instance of raw GenericOptional means that the instance will expand the methods as follows:
public class GenericOptional { public GenericOptional(Object someValue) {} public Object getValue() { return null; } public Optional getOptionalString() { return Optional.empty(); } }
However, if we consider the second fragment
public static void main(String[] args) { Object obj = new GenericOptional<>(Boolean.TRUE); GenericOptional<?> go = (GenericOptional) obj; Optional<String> os = go.getOptionalString(); }
we see that you are making a generic instance of GenericOptional . Even this parameter of type <?> , The compiler is not disabled, taking care of the type parameters, therefore the instance will expose the getOptionalString() parameter to a parameter, for example:
public Optional<String> getOptionalString() { return Optional.empty(); }
source share