I am using 1.8.0_25 and I get a compilation error. The error, however, is not that the call to choose is bad, but in the variable in which you want to add the result. Repeating an example:
static void testLowerBound() { List<? super Number> superNumber = new ArrayList<>(); List<? super Integer> superInteger = superNumber;
If you look at how T is replaced in the call, the parameters are used as List, losing information about the lower bound.
On the conclusion: everyone? not exactly "what can be assigned ...", but "a specific type that I do not want to name, which can be assigned ...". This is important because in your example you get 3 variables, 1 for each list, and another, different, for the selection result. Now, thanks to the declaration of choice, the substitution for T must satisfy the hierarchy of parameter classes. In the first case, you will need a replacement for <# 1 extends Integer> and <# 2 extends Number>. # 2 can be double, so the best key you have is that # 3 extends the number. In the second case, you will need to replace <# 1 super Integer> and <# 2 super Number>. Now this means that # 2 can be any of Number, Object, Serializable; # 1 adds Comparable and Integer to this list. The combinations can be Number, Object (and T must be Object); or Serializable, Integer (and T may be Serializable), so the best key that it has is that T is a list of an unknown type extending Object.
Of course, he could only get to Number, but you cannot get two boundaries for the same type variable, so it should be in that
source share