Using static imports and code reading quality?

Is it possible to consider a deterioration in the future readability of the code if I used them in the whole code? For example, using:

import static java.lang.Integer.*; 

so i can use this code

 int a = parseInt(scanner.nextLine()); 
+5
source share
2 answers

when should you use static imports? Very economical! Use it only when it is otherwise tempting to declare local copies of constants or abuse inheritance (Constant Interface Antipattern)

For your case, Importing all static elements from a class can be especially harmful for readability; if you only need one or two members, import them separately.

Link for more details.

+3
source

The only time I find it appropriate to use import static is to use a large number of Assert.assertXXX(...) when performing some tests (using JUnit, TestNG, etc.).

Every time I forced myself to name many static functions in a small amount of code, I better refactoring to improve readability (instead of doing import static ).

0
source

Source: https://habr.com/ru/post/1232563/


All Articles