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?