小编kev*_*vin的帖子

spring如何实现这项技术?

今天,我了解到我们可以使用spring的@AutoWired注释来完成自动注入,@ AutoWired可以在很多条件下使用,比如

@AutoWired
public void setInstrument(Instrument instrument){
  this.instrument = instrument;
}
Run Code Online (Sandbox Code Playgroud)

但我们也可以把这个@AutoWired放在私人领域

@AutoWired
private Instrument instrument;
Run Code Online (Sandbox Code Playgroud)

我想知道,春天如何将一个对象注入私有领域,我知道我们可以使用java的反射来获取一些元数据,当我使用反射在私有字段上设置一个对象时,这里出现了一个问题,以下是堆栈跟踪

 java.lang.IllegalAccessException: Class com.wire.with.annotation.Main can not access a member of class com.wire.with.annotation.Performer with modifiers "private"
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下吗?为什么spring可以将一个对象注入一个没有setter方法的私有字段.非常感谢

java spring

1
推荐指数
1
解决办法
191
查看次数

为什么打印输出不为空?

为什么会这样?

List<String> list = new ArrayList<String>();
list.add("aaa");
String s = list.get(0);
list.remove(0);
System.out.println(s);
Run Code Online (Sandbox Code Playgroud)

控制台说: aaa

有人可以帮我解释一下吗?我认为控制台应该是null,它应该是吗?

java null list arraylist

-2
推荐指数
1
解决办法
96
查看次数

标签 统计

java ×2

arraylist ×1

list ×1

null ×1

spring ×1