Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: code fix

...

This compliant solution uses a single display method and instanceof to distinguish between different types. As expected, the output is ArrayList, ArrayList, LinkedList, List is not recognized:

Code Block
bgColor#ccccff
class Overloader {
public class Overloader {
  private static String display(List<?> list) {
    return (
      list instanceof ArrayList ? "Arraylist" : 
      (list instanceof LinkedList ? "LinkedList" : 
      "List is not recognized")
    );
  }

  public static void main(String[] args) {
    // Single ArrayList
    System.out.println(display(new ArrayList<Integer>()));

    List<?>[] invokeAll = new List<?>[] {new ArrayList<Integer>(), 
    new LinkedList<String>(), new Vector<Integer>()};

    for (List<?> list : invokeAll) {
      System.out.println(display(list));
    }
  }
}

...