0

What im trying to do is to create a method that can handle being given most things. like ArrayLists, or tables or even ArrayLists of tables.

static void print(Object solution) {
    String ClassString = solution.getClass().getName();
    System.out.println(ClassString);
    switch (ClassString) {
    case "String[]":

        for (String S : (String[]) solution) {
            System.out.print(S + " ");
        }
        break;
    case "java.util.ArrayList":



        String Name = ((ArrayList) solution).get(0).getClass().getName();


        switch (Name){
        case "java.lang.String":
            for(String item : ((ArrayList) solution)){

            }
            break;
        }


//          for(String[] S: AList){
//              print(S);
//          }

        break;

    }

}

the problem i have is that the for(String item : ((ArrayList) solution)) gives the error Type mismatch: cannot convert from element type Object to String in eclipse, what am i missing that makes all of this click

0 Answers0