/* * A class is made generic by placing <> after its name in its declaration. * Inside the <>, put the name used to refer to the type. * The name is usually in all capital letters, but this is not required. * One class can have multiple parameterized types. To do so, put multiple type * names between the angle brackets, separated by commas. */ public class Named { // throughtout the class, T is used to refer to the type parameter private T object; private String name; public Named(T object, String name) { this.object = object; this.name = name; } public T getObject() { return object; } public String getName() { return name; } public void setObject( T newObject ) { this.object = newObject; } public void setName( String newName ) { this.name = newName; } public String toString() { return name + ": " + object.toString(); } /** * @param args */ public static void main(String[] args) { Named pi = new Named(3.14159,"pi"); Named e = new Named(2.718281828,"e"); System.out.println(pi); // this won't compile. What problems could arise? // Named namedThing = e; Named namedThing = e; System.out.println(namedThing); } }