File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class Derived2 extends GenericBase {} // No warning
1919// required: class or interface without bounds
2020
2121public class ErasureAndInheritance {
22- @ SuppressWarnings ("unchecked" )
22+ // @SuppressWarnings("unchecked")
2323 public static void main (String [] args ) {
2424 Derived2 d2 = new Derived2 ();
2525 Object obj = d2 .get ();
Original file line number Diff line number Diff line change 77public class ListMaker <T > {
88 List <T > create () { return new ArrayList <>(); }
99 public static void main (String [] args ) {
10- ListMaker <String > stringMaker = new ListMaker <>();
10+ // ListMaker<String> stringMaker = new ListMaker<>();
11+ ListMaker <String > stringMaker = new ListMaker <String >();
1112 List <String > stringList = stringMaker .create ();
1213 }
1314}
Original file line number Diff line number Diff line change 1- //// generics/Manipulation.java
2- //// (c)2021 MindView LLC: see Copyright.txt
3- //// We make no guarantees that this code is fit for any purpose.
4- //// Visit http://OnJava8.com for more book information.
5- //// {WillNotCompile}
6- //
7- //class Manipulator<T> {
8- // private T obj;
9- // Manipulator(T x) { obj = x; }
10- // // Error: cannot find symbol: method f():
11- // public void manipulate() { obj.f(); }
12- //}
13- //
14- //public class Manipulation {
15- // public static void main(String[] args) {
16- // HasF hf = new HasF();
17- // Manipulator<HasF> manipulator =
18- // new Manipulator<>(hf);
19- // manipulator.manipulate();
20- // }
21- //}
1+ // generics/Manipulation.java
2+ // (c)2021 MindView LLC: see Copyright.txt
3+ // We make no guarantees that this code is fit for any purpose.
4+ // Visit http://OnJava8.com for more book information.
5+ // {WillNotCompile}
6+
7+ class Manipulator <T > {
8+ private T obj ;
9+ Manipulator (T x ) { obj = x ; }
10+ // Error: cannot find symbol: method f():
11+ public void manipulate () {
12+ // obj.f();
13+ }
14+ }
15+
16+ public class Manipulation {
17+ public static void main (String [] args ) {
18+ HasF hf = new HasF ();
19+ Manipulator <HasF > manipulator =
20+ new Manipulator <>(hf );
21+ manipulator .manipulate ();
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments