<< January 17, 2007 | Home | January 19, 2007 >>

Thursday Java Generics Quiz

I'm going through O'Reilly's Java Generics and Collections by Maurice Naftalin and Philip Wadler to gain the necessary understanding of Java generics to effectively use it. I mentioned this book 53 days ago.

Here's something that surprised me. Can you guess if the following two classes will compile? And why?

import java.util.*;
class Foo {
  public Integer foo(List list) {
   return null;
  }
  public String foo(List list) {
    return null;
  }
}
import java.util.*;
class Bar {
  public Integer bar(List<Integer> integers) {
    return null;
  }
  public String bar(List<String> strings) {
    return null;
  }
}
Tags :