Code Design¶
Generic¶
Java¶
Single Abstract Method Interface (SAM) [CD002]¶
public class SamInteraceExample {
public static void main(String[] args) {
// This is using anonymous class
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Running using anonymous classes");
}
}).start();
// This is using lambda expression
new Thread(
() -> System.out.println("Running using lambda expression")
).start();
}
}