Since the primitive double is represented with the java.lang.Double class, shouldn't double.class equal java.lang.Double.class? (This of course also happens on other primitive types too)
System.out.println(double.class == Double.class);
Output:
Result: false
Double.class
is the class object corresponding to the wrapper type Double
. double
is actually not a class, but double.class
is the object used in reflection to indicate that an argument or return type has primitive type double
.
They are two distinct instances of Class<Double>
. This doesn't normally happen (for ordinary objects), but for wrapper classes, that's exactly the way to distinguish between fields of the primitive type and the wrapper type in reflection.
double
is a primitive type, Double
is a class type. There is a property on the Double
class called TYPE
:
For example System.out.println(double.class == Double.TYPE);
prints true.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.