Search code examples
javaclassprimitive

Why doesn't double.class equal java.lang.Double.class?


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

Solution

  • 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.