// generics/GenericHolder.java // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. public class GenericHolder { private T a; public GenericHolder() {} public void set(T a) { this.a = a; } public T get() { return a; } public static void main(String[] args) { GenericHolder h3 = new GenericHolder(); h3.set(new Automobile()); // type checked Automobile a = h3.get(); // No cast needed //- h3.set("Not an Automobile"); // Error //- h3.set(1); // Error } }