default keyword in Java

By | December 30, 2017
Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  1. default can be used in switch statement.
  2. default can be used in annotation, specifying the default value. For example:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface Todo {
    String author() default "Yash";
}

@Todo(author = "Yashwant")
public void incompleteMethod1() {
    //Some business logic is written
    //But it’s not complete yet
}