1

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

Matrix12
  • 446
  • 8
  • 19
  • Sorry but in http://stackoverflow.com/questions/20935977/what-is-the-easiest-way-to-have-cdi-and-jpa-in-java-se not found answer for my question. – Matrix12 Aug 02 '16 at 08:41

0 Answers0