我学习java,我想在setter上使用@Inject注释。
我有:
package mypackage;
import java.util.function.Consumer;
import javax.inject.*;
import java.lang.reflect.*;
public class MyTest {
@Inject
public static MyTest test;
public static String test2;
public static void main(String[] args) {
System.out.println("Works");
System.out.println(getNumber());
System.out.println(test2);
}
public static String getNumber() {
return test.number();
}
@Inject
public static void getNumber2(MyTest myTest) {
test2 = myTest.number();
}
}
package mypackage;
public class MyTest
{
public static String number()
{
return "2";
}
}
当我使用
时 @Inject
public static MyTest test;
然后test不为null,但是setter返回null,为什么?怎么解决?我用Gradle构建项目