public class A {
public <X> void method (List <? extends X> list) {
// processElement (list, list.get (0)); - compilation error
processElement ((List) list, (Object) list.get (0)); // compilation warning
}
public <T> void processElement (List <T> list, T object) {
}
public static class B <T extends I1 & I2> {
}
// You have to repeat declarations of generic types
public static class C <T extends I1 & I2> extends AB <T> {
}
}
public class A {
public <X> void method (List <? extends X> list) {
// processElement (list, list.get (0)); - Compile error
/ *
Definition? extends X as T for the type of the variable list (i.e. List <? extends X> -> List <T>).
The visibility of such a definition is limited to a block.
However, this definition is used in the same way as generic type T.
* /
List <T> list1 = alias <T> (list);
processElement (list1, list1.get (0)); // Correct
}
public <T> void processElement (List <T> list, T object) {
}
/ *
Alias N can be used wherever I1 & I3 can be used (in generics).
Alias N can be used wherever any of the interfaces I1 and I3 could be used.
Alias N can optionally be used as a variable type, the return value of a method, or a parameter of a method.
The alias has an access level.
* /
public alias N = I1 & I2;
public static class B <T extends N> {
}
// You have to repeat the declaration of one generic type instead of a complex bundle
public static class C <T extends N> extends AB <T> {
}
}
Source: https://habr.com/ru/post/93324/
All Articles