此场景中default关键字的用途是什么

时间:2016-01-28 08:19:51

标签: java spring-mvc

我看到一个问题,看起来像这样:

public @interface Controller {

/**
 * The value may indicate a suggestion for a logical component name,
 * to be turned into a Spring bean in case of an autodetected component.
 * @return the suggested component name, if any
 */
String value() default "";

}

什么是默认关键字,默认情况下为“”?

1 个答案:

答案 0 :(得分:1)

Controllerannotation

Java中的注释可能包含属性,在您的情况下,@Controller注释具有名为String的(value)属性。

使用注释时,您可能会省略为属性设置特定值,然后将使用默认值。例如:

@Controller //<-- here the value is `""`
public class SomeController { }

@Controller("other") //<-- but here value is set to "other"
public class OtherController { }