errorList = Arrays.asList(new Error("" /> errorList = Arrays.asList(new Error("" /> errorList = Arrays.asList(new Error(""/>

How to print the bounded type inferred by the compiler when using Generic types?

64 Views Asked by At

Consider the following snippet:

List<Exception> exceptionList = Arrays.asList(new Exception("344"));
List<Error> errorList = Arrays.asList(new Error("44"));

//consider a hypothetical function that can print the generic string corresponding
//to the type inferred by the following operation
showType((a == 4) ? exceptionList : errorList);
  • Here I was wondering if there is some way by which I can write a function that can print the Generic string corresponding to the type inferred by the compiler for the above operation?
  • eg: I feel that the type inferred must be something like List<? extends Throwable> by the compiler - I might be wrong as well but want to know how can we determine the inferred type by the compiler?
0

There are 0 best solutions below