[Solved] Why i am getting the following error in compilation: [closed]


Look at set1 and compare it to set2 notice that in the second case you specifying exactly what kind of objects set2 will hold but in the set1 you don’t so the compiler has no idea that you using your abc class (By the way class name should start with a capital). Here is the solution

  public static void main(String[] args) {
    ArrayList<ArrayList<abc>> set1 = new ArrayList<>(); // notice this line
    ArrayList<abc> set2 = new ArrayList<>();
    ArrayList<abc> set3 = new ArrayList<>();

    set1.add(set2);
    set1.add(set3);
    set2.add(new abc("xxxxxx"));
    set2.add(new abc("xxxxx yyyyy"));
    System.out.println(set2.get(0).txt);
    System.out.println(set1.get(0).get(0).txt);
    System.out.println(((abc) set1.get(0).get(0)).txt);
}

solved Why i am getting the following error in compilation: [closed]