user1357722 user1357722 - 6 months ago 13
Java Question

What is the difference between java.lang.Void and void?

In API


"The Void class is an uninstantiable placeholder class to hold a
reference to the Class object representing the Java keyword void."



  1. What is "uninstantiable" place holder class? When will
    java.lang.Void
    be used? If the class is "uninstantiable", what use is it?

  2. What is difference between
    java.lang.Void
    and
    void
    ?


Answer

The only point of Void is to hold Void.TYPE, which is sort of like void.class. If you have a reflective reference to a method that returns void, and you get its return type, it'll return Void.TYPE.

You cannot, and should not, use it for anything else.