Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
public static class Cage<T extends Animal> {
2
private Set<T> pen = new HashSet<T>();
3
4
public void add(T animal) {
5
pen.add(animal);
6
}
7
8
/* It's OK to put subclasses into a cage of
9
super class
10
*/
11
public void transferTo(Cage<? super T> cage) {
12
cage.pen.addAll(this.pen);
13
}
14
15
public void showAnimals() {
16
System.out.println(pen);
17
}
18
}
19
20