OnJava8-Examples/generics/Diamond.java

17 lines
459 B
Java
Raw Normal View History

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