About the basics of generics
Example)
List<String> list = new ArrayList<>();
list.add("aaa");
list.add(1); //Compile error
-[x] You can specify the type to be included in List
Prohibiting new type variable E in generic typeclass
class Owner<E>{
E createObject(){
return new E();
}
}
Compile error
-[] Task 1 -[x] Task 2
When you declare List
class List<String> {
private String element;
String get() {
return element;
}
void put(String e) {
this.element = e;
}
}
Is created internally. (Unsettled)
Recommended Posts