I can't call a getClass() method on a primitive field, can I?

I have a little issue with my code. The last expression is supposed to be true, but the program returns false. The variable result is a double with the value of 2.5. I tried to figure out what’s wrong with the help of this piece of code

import java.text.DecimalFormat;


private static final DecimalFormat df = new DecimalFormat("#.##");


System.out.println("Result is: " + result);
System.out.println("The datatype of result is: " + result.getClass().getName());

System.out.println("String.valueOf(result) is: " + String.valueOf(result));
System.out.println("The datatype of String.valueOf(result) is: " + String.valueOf(result).getClass().getName());

System.out.println("df.format(result) is: " + df.format(result));
System.out.println("The datatype of df.format(result) is: " + df.format(result).getClass().getName());

System.out.println("Is String.valueOf(result) equal to df.format(result): " + String.valueOf(result).equals(df.format(result)));

However, my IntelliJ IDEA “cannot resolve method getClass()” when applied to result directly (the second line of the code). Could you tell me please why that’s so? Debug my debugging, in other words!

If result is a double, which is a primitive type, rather than a Double object,
then result does not have methods, so result.getClass() won’t work.

.getClass() only works on objects; it won’t work on primitive types in Java.