Would it be considered worsening the future readability of the code if I used them throughout the code? For example using:
import static java.lang.Integer.*;
so I can use this code
int a = parseInt(scanner.nextLine());
Would it be considered worsening the future readability of the code if I used them throughout the code? For example using:
import static java.lang.Integer.*;
so I can use this code
int a = parseInt(scanner.nextLine());
when should you use static import? Very sparingly! Only use it when you'd otherwise be tempted to declare local copies of constants, or to abuse inheritance (the Constant Interface Antipattern)
For your case Importing all of the static members from a class can be particularly harmful to readability; if you need only one or two members, import them individually.
The only time I think it's appropriate to use import static
is when using a lot of Assert.assertXXX(...)
when doing some testing (with JUnit, TestNG, etc.).
Every time I caught myself calling a lot of some static functions in a small amount of code, I better refactor to improve readability (instead of doing an import static
).