Java Reference
In-Depth Information
Listing 2.1. Behavior parameterization: filtering apples with predicates
This is unnecessary overhead; can you do better? Java has a mechanism called anonymous
classes , which let you declare and instantiate a class at the same time. They enable you to
improve your code one step further by making it a little more concise. But they're not entirely
satisfactory. Section 2.3.3 shows a short preview of how lambda expressions can make your code
more readable before we discuss them in detail in the next chapter.
2.3.1. Anonymous classes
Anonymous classes are like the local classes (a class defined in a block) that you're already
familiar with in Java. But anonymous classes don't have a name. They allow you to declare and
instantiate a class at the same time. In other words, they allow you to create ad hoc
implementations.
 
Search WWH ::




Custom Search