2

Just read some source code from Spring-web-4.2.4, found that the ControllerAdvice (annotation) is pretty interesting:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface ControllerAdvice {
  @AliasFor("basePackages")
  String[] value() default {};

  @AliasFor("value")
  String[] basePackages() default {};

  //......
}

I do not consider default {} as the new feature of Java 8?

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Will Hu
  • 149
  • 2
  • 15
  • "default" is new feature of Java 8 but only for "interface", not for "@interface". – Dmitry Gorkovets Jan 11 '17 at 12:08
  • Possible duplicate of [Interface with default methods vs Abstract class in Java 8](http://stackoverflow.com/questions/19998454/interface-with-default-methods-vs-abstract-class-in-java-8) – Andremoniy Jan 11 '17 at 12:10
  • Later found that it is just Java annotation behaviour, http://stackoverflow.com/questions/588056/interface-default-declaration-usage-in-java explained before..Thanks everyone. – Will Hu Jan 11 '17 at 12:20

2 Answers2

2

In Java @interface is a some kind of reserved word (keyword) for defining annotations. So you can be sure that the class you listed above is an annotation definition. In this classes default keyword could be used to define default value for annotation properties. This feature was introduced at the same time as annotations were introduced in the language.

bsiamionau
  • 8,099
  • 4
  • 46
  • 73
  • You are absolutely right.. http://stackoverflow.com/questions/588056/interface-default-declaration-usage-in-java Explains a bit around it. Thanks dude. – Will Hu Jan 11 '17 at 12:18
2
  1. The default keyword is used in annotations to set a default value for a corresponding annotation type (it, in turn, allows you not to specify a value of this type every time you write the annotation);

  2. {} is just an array literal which means an empty array.

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142