When I have a Java generic function like:
<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 happens at compile time. So what I'm asking is, how do I get the compiler to tell me some information (the inferred type) it has during compilation, but that doesn't make it into the .class file?
One thing I could do is try to assign the result to variables of various types, e.g.:
// Compiles, so inferred type is at least Throwable.
Throwable foo = choose(new EOFException(), new FileNotFoundException());
// If this compiles, T must be Map or something that implements Map.
Map foo = choose(new HashMap(), new TreeMap());
But that's rather indirect. I'd like the compiler to tell me what type it infers for T, rather than me having to play 20 questions.