MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / GenericHolder

Class GenericHolder

generics/GenericHolder.java:6–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4// Visit http://OnJava8.com for more book information.
5
6public class GenericHolder<T> {
7 private T a;
8 public GenericHolder() {}
9 public void set(T a) { this.a = a; }
10 public T get() { return a; }
11 public static void main(String[] args) {
12 GenericHolder<Automobile> h3 =
13 new GenericHolder<>();
14 h3.set(new Automobile()); // type checked
15 Automobile a = h3.get(); // No cast needed
16 //- h3.set("Not an Automobile"); // Error
17 //- h3.set(1); // Error
18 }
19}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected