Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Code Block
bgColor#FFCCCC
public class Overloader {
  private static String display(ArrayList&lt;Integer&gt;ArrayList<Integer> a) {
    return &quot;ArrayList&quot;"ArrayList";
  }

  private static String display(LinkedList&lt;String&gt;LinkedList<String> l) {
    return &quot;LinkedList&quot;"LinkedList";
  }

  private static String display(List&lt;?&gt;List<?> l) {
    return &quot;"List is not recognized&quot;";
  }

  public static void main(String[] args) {
    // Array of lists
    List&lt;?&gt;List<?>[] invokeAll = new List&lt;?&gt;List<?>[] {new ArrayList&lt;Integer&gt;ArrayList<Integer>(), 
    new LinkedList&lt;String&gt;LinkedList<String>(), new Vector&lt;Integer&gt;Vector<Integer>()};

    for(List&lt;?&gt;List<?> i : invokeAll) {
      System.out.println(display(i));
    }
  }
}

...

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

  public static void main(String[] args) {
    List&lt;?&gt;List<?>[] invokeAll = new List&lt;?&gt;List<?>[] {new ArrayList&lt;Integer&gt;ArrayList<Integer>(), 
    new LinkedList&lt;String&gt;LinkedList<String>(), new Vector&lt;Integer&gt;Vector<Integer>()};

    for(List&lt;?&gt;List<?> i : invokeAll) {
      System.out.println(display(i));
    }
  }
}

...

MET32-J. Ensure that constructors do not call overridable methods&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      12. Methods (MET)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      MET34-J. Follow the general contract when implementing the compareTo method