What does int.class mean

前端 未结 3 647
小鲜肉
小鲜肉 2020-12-06 05:38

In java int, float and etc., are primitive types. Wrapper classes are used in case we need to use it with generics. But still the following declaration works in java,

<
3条回答
  •  心在旅途
    2020-12-06 06:07

    A class literal is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type void, followed by a `.' and the token class.

    1. An enum is a kind of class and an annotation is a kind of interface.
    2. Every array also belongs to a class that is reflected as a Class object that is shared by 3. all arrays with the same element type and number of dimensions.
    3. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and
    4. The keyword void are also

    represented as Class objects.

    So System.out.println(int.class); will print int whereas System.out.println(Integer.class); will print class java.lang.Integer.

提交回复
热议问题