PROGRAMMING

m9/ JAVA
REMEMBERS




Last update:   26-07-2021

IMPORT STATIC

p107 Sometimes the constants from a utilitiy class are used heavely. You can use import static to avoid qualifying with the class name.
 
import static java.lang.Math.PI; // Look Here
import static java.lang.Math.E;

class App {

    public static void main(String[] args) {

        System.out.println(PI); // 3.141592653589793
        System.out.println(E); // 2.718281828459045
    }
}
... 2 lines
 
! It can have negative impact on readabilty and testability. You dump potentialy large classes into your namespace.
 
import static java.lang.Math.*; // Look Here

class App {

    public static void main(String[] args) {

        System.out.println(PI);
        System.out.println(E);
    }
}
... 1 lines
 

Questions    
Enum

        A B C D E F
🔔
1/1