Antoine
Antoine

Reputation: 4734

How to import statically all variables at the same time in eclipse when use "Add import" in eclipse?

For example i have ConstantsClass.java with :

private static final String DUMMY_STRING = "dummy string";

and MyClass.java :

import net.foo.ConstantsClass;

public void doStuff(){
  String value = ConstantsClass.DUMMY_STRING ;
  doStuff2(ConstantsClass.DUMMY_STRING);
}

When i add a static import for the first DUMMY_STRING with "Add Import"(Ctrl+Shift+M), i will have

import static net.foo.ConstantsClass.DUMMY_STRING;
import net.foo.ConstantsClass;

public void doStuff(){
  String value = DUMMY_STRING ;
  doStuff2(ConstantsClass.DUMMY_STRING);
}

If i want to do it for all variables in this class, i have to make "Add import" for each "DUMMY_STRING", is there a way to do it for all "DUMMY_STRING" in one command ?

Upvotes: 2

Views: 190

Answers (1)

nanda
nanda

Reputation: 24788

Go to the preference. Find Java -> Code Style -> Organize Imports and change the value of ***Number of static imports needed for .**** to '1'

enter image description here

Upvotes: 1

Related Questions