File tree Expand file tree Collapse file tree 2 files changed +3
-5
lines changed Expand file tree Collapse file tree 2 files changed +3
-5
lines changed Original file line number Diff line number Diff line change 3
3
// We make no guarantees that this code is fit for any purpose.
4
4
// Visit http://OnJava8.com for more book information.
5
5
6
- class Bob {}
7
-
8
6
public class Diamond <T > {
9
7
public static void main (String [] args ) {
10
- GenericHolder <Bob > h3 = new GenericHolder <>();
11
- h3 . set ( new Bob () );
8
+ GenericHolder <Automobile > h3 =
9
+ new GenericHolder <>( );
12
10
}
13
11
}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ public GenericHolder() {}
10
10
public T get () { return a ; }
11
11
public static void main (String [] args ) {
12
12
GenericHolder <Automobile > h3 =
13
- new GenericHolder <>();
13
+ new GenericHolder <Automobile >();
14
14
h3 .set (new Automobile ()); // type checked
15
15
Automobile a = h3 .get (); // No cast needed
16
16
//- h3.set("Not an Automobile"); // Error
You can’t perform that action at this time.
0 commit comments