From 8136464a6e32d31e6a5e3cb3b8c32949b2dbe060 Mon Sep 17 00:00:00 2001 From: Kirti Deo Date: Mon, 20 Aug 2018 21:12:40 +0530 Subject: [PATCH] BAEL-2024 : ClassCastException : Fixing review comments --- .../ClassCastException.java | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/classcastexception/ClassCastException.java b/core-java/src/main/java/com/baeldung/classcastexception/ClassCastException.java index 754713dadb..64d56e6438 100644 --- a/core-java/src/main/java/com/baeldung/classcastexception/ClassCastException.java +++ b/core-java/src/main/java/com/baeldung/classcastexception/ClassCastException.java @@ -8,32 +8,16 @@ public class ClassCastException { public static void main(String[] args) { - List> personList = new ArrayList>(); + List> strList = new ArrayList>(); // To correct the Exception at line #18, modify the line #11 code as: // List> personList = new ArrayList >(); // Line #18 code as personList.add(Arrays.asList(personArray)); - Person p1 = new Person(1, "John"); - Person p2 = new Person(2, "Snow"); - Person[] personArray = new Person[] { p1, p2 }; - personList.add((ArrayList) Arrays.asList(personArray)); - System.out.println("Personlist: " + personList); + String p1 = new String("John"); + String p2 = new String("Snow"); + String[] strArray = new String[] { p1, p2 }; + strList.add((ArrayList) Arrays.asList(strArray)); + System.out.println("String list: " + strList); } } - -class Person { - int id; - String name; - - Person(int id, String name) { - this.id = id; - this.name = name; - } - - @Override - public String toString() { - return "Person [id=" + id + ", name=" + name + "]"; - } - -}