Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using static imports and code readability quality?

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());
like image 217
The Law Avatar asked Sep 29 '15 18:09

The Law


1 Answers

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.

Link for more detail

like image 177
Rohit Jain Avatar answered Oct 21 '22 16:10

Rohit Jain