Java基础知识
Posted jialilue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java基础知识相关的知识,希望对你有一定的参考价值。
@Override
表示重写
编译器可以验证@Override下面的方法名是否是父类中所有的
@Autowired
使用@Autowired 注解来实现依赖注入
可以用在属性、setter方法和构造器上
用在属性上
@Component("fooFormatter") public class FooFormatter { public String format() { return "foo"; } }
@Component public class FooService { @Autowired private FooFormatter fooFormatter; }
The annotation can be used directly on properties, therefore eliminating the need for getters and setters:
In the above example, Spring looks for and injects fooFormatter when FooService is created.
用在setter上
public class FooService {
private FooFormatter fooFormatter;
@Autowired public void setFooFormatter(FooFormatter fooFormatter) { this.fooFormatter = fooFormatter; } }
The @Autowired annotation can be used on setter methods. In the above example, when the annotation is used on the setter method, the setter method is called with the instance of FooFormatter when FooServiceis created:
用在构造器上
public class FooService { private FooFormatter fooFormatter; @Autowired public FooService(FooFormatter fooFormatter) { this.fooFormatter = fooFormatter; } }
The @Autowired annotation can also be used on constructors. In the above example, when the annotation is used on a constructor, an instance of FooFormatter is injected as an argument to the constructor when FooService is created:
String...
可变参数
相当于String[]
以上是关于Java基础知识的主要内容,如果未能解决你的问题,请参考以下文章