The javadoc for Void
says:
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.
but the constructor is simply:
private Void() {}
and this code instantiates a Void
:
Constructor<Void> c = Void.class.getDeclaredConstructor();
c.setAccessible(true);
Void v = c.newInstance(); // Hello sailor
So Void
is not uninstantiable.
Would there have been a way to make Void
truly uninstantiable?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…