Can we declare a member variable as static for which we are doing constructor injection?

Viewed 13

To use a member variable in static function I need to declare that member variable as static. Is there anything wrong in declaring static fields and injecting them via constructor injection in multithreaded environment ?

@Named
public class QueryHelper {
  // Anything wrong to declare it static and injecting it via constructor injection ?
   private static QueryUtil queryUtil;

    @Inject
    QueryHelper(final QueryUtil queryUtil) {
        this.queryUtil = queryUtil;
    }

    public static List<Contracts> getContracts() {
       
      // .. some code

       queryUtil.someFunction();


      // ..some code
      return contractList();
    }
}
0 Answers
Related