Code Design

Generic

Exception vs Boolean [CD001]

Exceptions are generally the way to go for things where failure is not expected as an option. Boolean return values are the way to go for things where failure might be an expected result sometimes.

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();
     }
}