I don't understand why I'm getting a warning with the following code:
public static boolean isAssignableFrom(Class clazz, Object o) {
return clazz.isAssignableFrom(o.getClass());
}
Unchecked call to
isAssignableFrom(Class<?>)
as a member of raw typejava.lang.Class
When I use the isInstance
method instead (which provides identical results from what I understand), I don't get a warning:
public static boolean isAssignableFrom(Class clazz, Object o) {
return clazz.isInstance(o);
}
Because Class
is a generic type, and you aren't telling Java that the Object
must be an instance of the class. Change
public static boolean isAssignableFrom(Class clazz, Object o)
to something like
public static <C> boolean isAssignableFrom(Class<C> clazz, C o)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With