When I have a general Java function, for example:
<T> T choose(T a, T b) { }
and I call it from somewhere, how can I find out what type is inferred for T?
Edit: type inference occurs at compile time. So I ask, how do I get the compiler to tell me some information (the supposed type) that it has at compile time, but that does not make it in the .class file?
The only thing I can do is try to assign the result to variables of various types, for example:
Throwable foo = choose(new EOFException(), new FileNotFoundException());
Map foo = choose(new HashMap(), new TreeMap());
But it is rather indirect. I would like the compiler to tell me what type it has for T, instead of having to play 20 questions.
source
share