2015-04-20 15:36:01 -07:00
|
|
|
|
//: generics/Holder3.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
|
|
|
|
|
public class Holder3<T> {
|
|
|
|
|
private T a;
|
|
|
|
|
public Holder3(T a) { this.a = a; }
|
|
|
|
|
public void set(T a) { this.a = a; }
|
|
|
|
|
public T get() { return a; }
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
Holder3<Automobile> h3 =
|
2015-05-05 11:20:13 -07:00
|
|
|
|
new Holder3<>(new Automobile());
|
2015-04-20 15:36:01 -07:00
|
|
|
|
Automobile a = h3.get(); // No cast needed
|
|
|
|
|
// h3.set("Not an Automobile"); // Error
|
|
|
|
|
// h3.set(1); // Error
|
|
|
|
|
}
|
|
|
|
|
} ///:~
|