Does “instanceof Void” always return false?

前端 未结 4 391
爱一瞬间的悲伤
爱一瞬间的悲伤 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:17

    No. To make it return true you have to call it and pass an argument of type Void. But the constructor of class Void is private, so you cannot call it. Moreover, this class is final, so you cannot even extend it. Thus you cannot create an instance of class Void. But it is needed to make your method to return true.

    BTW: If you really want to do it, call the constructor of Void by reflection. But I can think about this as a system abuse exercise. Good luck.

提交回复
热议问题