Does “instanceof Void” always return false?

前端 未结 4 382
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 12:13

Can this method return true somehow?

public static  boolean isVoid(T t)
{
    return t instanceof Void;
}
4条回答
  •  独厮守ぢ
    2021-01-01 12:18

    No:

    Constructor cv = Void.class.getDeclaredConstructor(); 
    cv.setAccessible(true); 
    Void v = cv.newInstance(); 
    System.out.println(v instanceof Void); //-> true
    

提交回复
热议问题