You already know that this is primitive because you write int.class.
You’d like to have something like public boolean isPrimitive(Object object).
But this will not work.
The problem is that when you call isPrimitive(intVariable)intVariable will be auto-boxed to Integer which is already not a primitive. So for int intVariable our method will return false.
Let’s take a look at some “primitive wrappers”
Check if object is Integer
Check if object is Boolean
Check if object is Character
Check if object is Byte
Check if object is Short
Check if object is Long
Check if object is Float
Check if object is Double
So all we can do is to check if an object is a primitive in wider meaning - “wrapper for primitive”
Check if object is primitive wrapper
Since this is “isWiderPrimitive” I would include also String and Void (yes there is the Void class in Java)
The final version of our isWiderPrimitive method looks like this