Onwards into the Interfaces and Inheritance tutorial, starting with Interfaces. This is a short one, starting with an overview and moving onto the more interesting topic of how to evolve or update interfaces.
The Learning the Java Language trail moves onto Annotations. Annotations are a form of metadata that can provide data about the program and there is more to them than you might think…
- Declaring An Annotation Type
- Predefined Annotations
- Annotations That Apply To Other Annotations
- Java SE 8 Type Annotations and Pluggable Type Systems
Just as you were thinking you were finally at the end of the Classes And Objects tutorial, along comes Enums!
enumtypes to represent a fixed set of constants.
enumdeclaration defines a class which implicitly extends java.lang.Enum
- The class includes a static
valuesmethod that returns an array of all values.
Method References are part of Lambda Expressions in The Java Tutorials but that’s a pretty big topic so I’m splitting it out here. It’s also a little hard to follow the examples if you are not familiar with Generics.
When a lambda expression does nothing but call an existing method, it’s often clearer to refer to the existing method by name. We can do this with a Method Reference.
The next section deals with Lambda Expressions with are new to Java 8 and fairly mind-bending. A Lambda Expression is a more succinct version of an Anonymous Class.
- Specify Search Criteria Code in a Local Class
- Specify Search Criteria Code in an Anonymous Class
- Specify Search Criteria Code with a Lamba Expression
- Use A Standard Functional Interface with Lambda Expressions
- Use Aggregate Operations That Accept Lambda Expressions As Parameters
- An Example Using A Lambda Expression in a Gui
- Target Typing
A large chunk of the Classes and Objects tutorial deals with Nested Classes, Inner Classes, Local Classes,Anonymous Classes, Lambda Expressions, and Method References. All these provide ways to:
- logically group classes that are only used in one place
- increase use of encapsulation as the outer class can have private members that the inner class can access
- create more readable and maintainable code
The end of the tutorial has some suggestions about which approach to use. I’m starting with this before diving into the detail:
The Classes And Objects tutorial starts off gently enough but then gets increasingly more mind-bending as it dives into Inner Classes, Local Classes, Anonymous Classes, Lambda Expressions, Method References and introductions to Generics. It’s pretty long too so I’m splitting it out, starting with notes on the basics.