Category: Java

Java 8 Series: Constructor and Method References

This series’ recent post showed that lambda expressions can be assigned to variables whose type is a functional interface, e.g. like this: Runnable runForrest = () -> Forrest.run();. Today we’ll learn how to initialize such functional interface-typed variables with method and constructor references. Picking up the previous example that means that we’ll see how to directly reference the Forrest.run() method.

Read More

Java 8 Series: Lambda Expressions

In my daily work I often switch from the development on JavaScript-based frontends to Java-based backends. Thereby it occasionally happens that I intentionally start to write function() {... at places where actually anonymous classes are required. Thanks to Java 8 such functional language syntax will be a valid option. Namely you will be able to substitute anonymous classes with lambda expressions in cases where you actually just want to pass functionality.

Read More

Java 8 Series: Default and Static Interface Methods

Currently in Java 7, if you enhance an interface with a new method declaration, or if you switch to a third-party library’s new version with an enhanced API, then this generally leads to a break of existing implementations in your code. So you must define the new method in existing implementations respectively adapt the versions of depending libraries in order to get rid of compile errors. However, in Java 8 this won’t be always necessary.

Read More