OnJava8-Examples/generics/Holder3.java

17 lines
478 B
Java
Raw Normal View History

2015-06-15 17:47:35 -07:00
//: generics/Holder3.java
// <20>2015 MindView LLC: see Copyright.txt
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 =
new Holder3<>(new Automobile());
Automobile a = h3.get(); // No cast needed
// h3.set("Not an Automobile"); // Error
// h3.set(1); // Error
}
} /* Output: (None) *///:~