Is there any way in Java to get the compile time type of a reference at runtime?
Example:
private void doSomething(final Object o)
{
// do somthing
}
final Number n = 1;
doSomething(n);
final Object o = 1;
doSomething(o);
final Integer i = 1;
doSomething(i);
1st call –> Number
2nd call –> Object
3rd call –> Integer
Edit: This is a very simplified version of the problem. What i am trying to do is to detect(instead of being told) inside a framework metadata about objects being passed. What could happen is, that the method gets first called with an Integer and then with a Double, both declared as Number.
The only way I see is to use overloading. But you would need to specify a overlading method for each class of the inheritance relation to exclude sub classes.