I'm using the Eclipse JDT Null annotation processor and I'm getting some weird behaviour when using java.lang.Class.
package test; import org.eclipse.jdt.annotation.Nullable; public class AnnotationSpul { @Nullable public <V> V get1(Class<V> type) { return get2(type); //This line has a warning } @Nullable public <V> V get2(Class<V> type) { return null; } } This is my package info:
@NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD }) package test; import static org.eclipse.jdt.annotation.DefaultLocation.FIELD; import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER; import static org.eclipse.jdt.annotation.DefaultLocation.RETURN_TYPE; import org.eclipse.jdt.annotation.NonNullByDefault; The warning I get is: "The expression of type '@NonNull Class' needs unchecked conversion to conform to '@NonNull Class<@Nullable V>'"
I don't understand why I get the warning. The method signatures are exactly the same, so why does the value passed need conversion? Why is type inferred as @NonNull Class<V> in one method and @NonNull Class<@Nullable V> in the other?
public <V> @Nullable V get1(...)rather than@Nullable public <V> V get1(...).