Skip to content

Commit 8136464

Browse files
committed
BAEL-2024 : ClassCastException : Fixing review comments
1 parent 8c874c0 commit 8136464

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

‎core-java/src/main/java/com/baeldung/classcastexception/ClassCastException.java‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,16 @@ public class ClassCastException {
88

99
public static void main(String[] args) {
1010

11-
List<ArrayList<Person>> personList = new ArrayList<ArrayList<Person>>();
11+
List<ArrayList<String>> strList = new ArrayList<ArrayList<String>>();
1212
// To correct the Exception at line #18, modify the line #11 code as:
1313
// List<List<Person>> personList = new ArrayList <List<Person>>();
1414
// Line #18 code as personList.add(Arrays.asList(personArray));
15-
Person p1 = new Person(1, "John");
16-
Person p2 = new Person(2, "Snow");
17-
Person[] personArray = new Person[] { p1, p2 };
18-
personList.add((ArrayList<Person>) Arrays.asList(personArray));
19-
System.out.println("Personlist: " + personList);
15+
String p1 = new String("John");
16+
String p2 = new String("Snow");
17+
String[] strArray = new String[] { p1, p2 };
18+
strList.add((ArrayList<String>) Arrays.asList(strArray));
19+
System.out.println("String list: " + strList);
2020

2121
}
2222

2323
}
24-
25-
class Person {
26-
int id;
27-
String name;
28-
29-
Person(int id, String name) {
30-
this.id = id;
31-
this.name = name;
32-
}
33-
34-
@Override
35-
public String toString() {
36-
return "Person [id=" + id + ", name=" + name + "]";
37-
}
38-
39-
}

0 commit comments

Comments
 (0)