File tree Expand file tree Collapse file tree
src/main/java/com/ab/generics/erasure Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .ab .generics .erasure ;
2+
3+ import java .util .List ;
4+
5+ /**
6+ * @author Arpit Bhardwaj
7+ */
8+ public class Erasure <T ,B extends Comparable <B >> {
9+ public void unBounded (T param ){
10+
11+ }
12+ public void lists (List <String > param1 , List <List <T >> param2 ){
13+
14+ }
15+ public void bounded (B param ){
16+
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .ab .generics .erasure ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .Iterator ;
5+ import java .util .List ;
6+
7+ /**
8+ * @author Arpit Bhardwaj
9+ */
10+ public class Legacy {
11+ public static void main (String [] args ) {
12+ List list = new ArrayList ();
13+ //not same as
14+ //List<Object> list = new ArrayList<>();
15+
16+ list .add ("abc" );
17+ list .add (1 );
18+ list .add (new Object ());
19+
20+ List <Integer > integers = new ArrayList ();
21+ integers = list ;
22+ List <String > strings = new ArrayList ();
23+ //list = strings;
24+
25+ Iterator iterator = list .iterator ();
26+ while (iterator .hasNext ()){
27+ System .out .println (iterator .next ());
28+ }
29+
30+ //Leads to ClassCastException
31+ for (Integer elem :integers ) {
32+ System .out .println (elem );
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments