0

excuse me for asking such a generic question, but I can't phrase it better. I have seen code of this style fairly often, but have not yet used it.

variable= someClass.someMethod(new someOtherClass(){
      methodDeclaration(){
      }
});

If you don't know what I mean, the top answer could serve as an example: How do I check if the user is pressing a key?

When is this used? Are there any examples of problems that can only be solved by such code?

Community
  • 1
  • 1
Octom
  • 27
  • 1
  • 3
  • This article should clarify things: http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html . Anyways theres definitely a duplicate somewhere around here, I'm just too lazy to search –  Feb 26 '16 at 00:57
  • This is an example of an anonymous class. Your answer should be in [this question](http://stackoverflow.com/questions/355167/how-are-anonymous-inner-classes-used-in-java). – No Name Feb 26 '16 at 00:59
  • This code snippet is using an inline anonymous class. Just have a look at the Oracle trails for a good explanation. – Tim Biegeleisen Feb 26 '16 at 00:59

0 Answers0