I learning java and I want to use @Inject annotation on setters.
I have:
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";
}
}
When I used
@Inject
public static MyTest test;
then test is not null, but with setters return null, Why? How to fix it? I build project with Gradle