Fixed issue #46

This commit is contained in:
Bruce Eckel 2021-04-18 09:35:27 -06:00
parent a75a55dc81
commit 5ef986390e
2 changed files with 3 additions and 5 deletions

View File

@ -3,11 +3,9 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
class Bob {}
public class Diamond<T> {
public static void main(String[] args) {
GenericHolder<Bob> h3 = new GenericHolder<>();
h3.set(new Bob());
GenericHolder<Automobile> h3 =
new GenericHolder<>();
}
}

View File

@ -10,7 +10,7 @@ public class GenericHolder<T> {
public T get() { return a; }
public static void main(String[] args) {
GenericHolder<Automobile> h3 =
new GenericHolder<>();
new GenericHolder<Automobile>();
h3.set(new Automobile()); // type checked
Automobile a = h3.get(); // No cast needed
//- h3.set("Not an Automobile"); // Error