What returns int.class

I understand what wrappers are, but from the documentation you seem to be able to get an instance of an object of a class of type int. Does this return a wrapper or any instance of an int class? Because it would not make sense if it happened, due to generics and erasure of styles. Isn't it true that you can only get class instances of actual classes, not primitives? When they say do they represent the shell of something else?

This is what JavaDoc says and why I got confused

TYPE

public static final Class TYPE

    The Class instance representing the primitive type int.

    Since:
        JDK1.1
+5
source share
1 answer

Isn't it true that you can only get class instances of actual classes, not primitives?

Sorting.

" ". , . Class[] , - public void test(Integer x) public void test(int x).

, .

, java.lang.Void.TYPE:

 Class<Void> x = void.class;

Javadoc:

/**
 * Determines if the specified <code>Class</code> object represents a
 * primitive type.
 *
 * <p> There are nine predefined <code>Class</code> objects to represent
 * the eight primitive types and void.  These are created by the Java
 * Virtual Machine, and have the same names as the primitive types that
 * they represent, namely <code>boolean</code>, <code>byte</code>,
 * <code>char</code>, <code>short</code>, <code>int</code>,
 * <code>long</code>, <code>float</code>, and <code>double</code>.
 *
 * <p> These objects may only be accessed via the following public static
 * final variables, and are the only <code>Class</code> objects for which
 * this method returns <code>true</code>.
 *
 * @return true if and only if this class represents a primitive type
 *
 * @see     java.lang.Boolean#TYPE
 * @see     java.lang.Character#TYPE
 * @see     java.lang.Byte#TYPE
 * @see     java.lang.Short#TYPE
 * @see     java.lang.Integer#TYPE
 * @see     java.lang.Long#TYPE
 * @see     java.lang.Float#TYPE
 * @see     java.lang.Double#TYPE
 * @see     java.lang.Void#TYPE
 * @since JDK1.1
 */
public native boolean isPrimitive();
+7

All Articles