Why am I getting a clear warning?

I do not understand why I am getting a warning with the following code:

public static boolean isAssignableFrom(Class clazz, Object o) { return clazz.isAssignableFrom(o.getClass()); } 

An unverified call to isAssignableFrom(Class<?>) As an element of the original java.lang.Class type

When I use the isInstance method isInstance (which gives identical results from what I understand), I don't get the warning:

 public static boolean isAssignableFrom(Class clazz, Object o) { return clazz.isInstance(o); } 
+5
source share
1 answer

Because Class is a generic type, and you are not telling Java that Object should be an instance of a class. The change

 public static boolean isAssignableFrom(Class clazz, Object o) 

to something like

 public static <C> boolean isAssignableFrom(Class<C> clazz, C o) 
+2
source

All Articles