java - TypeUtils says "null" is instance of "Object.class"? -


regarding following code org.apache.commons.lang3.reflect.typeutils says null type of object.class. isn't incorrect ?

public static void main(string args[]) {      boolean bool = null;      if (typeutils.isinstance(bool, object.class)) {         system.out.println("bool isinstance object-true");     } else {         system.out.println("bool isinstance object-false");     }   } 

i agree you. isinstance() method misleading. should rather isassignable() since documentation indicates :

checks if given value can assigned target type following java generics rules.

and null not instance of object class since null not instance.

but result accurate according documentation since null can assigned object type. , when implementation, can see code calls isassignable() method :

public static boolean isinstance(final object value, final type type) {     if (type == null) {         return false;     }      return value == null ? !(type instanceof class<?>) || !((class<?>) type).isprimitive()             : isassignable(value.getclass(), type, null); } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -