February 2020
Intermediate to advanced
412 pages
9h 36m
English
Prior to Java 8, you might have leveraged anonymous classes to implement interfaces, such as Runnable, on the fly, as shown in the following code snippet:
public class A_01 { public static void main(String[] args) { Runnable runnable = new Runnable() { @Override public void run() { System.out.println("run() was called!"); } }; runnable.run(); }}
The output is as follows:
run() was called!
To implement Runnable without declaring an explicit class, you had to implement its run() abstract method in a block immediately after the constructor. This created a lot of boilerplate and became a major pain point with Java development, becoming a barrier to using functional programming in Java. Thankfully, ...
Read now
Unlock full access