Originally posted by Rob Prime:
Autoboxing would turn the int into an Integer, and would lead to Integer.class, not int.class
Hence the use of reflection. All the primitive wrapper classes have a final static field TYPE.
Given an Integer object, it is impossible to determine whether it was resolved using autoboxing or calling Integer.valueOf manually. You could filter out new Integer calls by using reflection to check for reference equality with the cache inside Integer, but that only works for values between -128 and 127.
Agreed, but the OP
specifically mentioned that the variable would be a primitive.
As far as the detailed requirement posted much later is concerned, this wouldn't be a solution at all. That's why I had asked
but why do you think you need this and how do you plan to use it?
[ December 30, 2008: Message edited by: Darryl Burke ]