0

I'm still rather new to anonymous classes could anyone explain to me why this doesn't work?

List<String> instanceOfAnonymousClass = new ArrayList<string>(){
  public void printSomething(){
    System.out.println("something");
  };
};
instanceOfAnonymousClass.printSomething();

Eclipse says

"The method printSomething() is undefined for the type List<String>"

So it won't even compile

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
Artemio Ramirez
  • 1,116
  • 1
  • 10
  • 23

0 Answers0