JAVA

  minte9
REMEMBERS




Last update:   02-11-2021

Utility

p107 Sometimes the constants from a utilitiy class are used heavely.
 
/**
 * Import static
 * 
 * You can use import static to avoid ...
 * qualifying with the class name. 
 */

package com.minte9.effective.import_static;

import static java.lang.Math.PI; // Look Here
import static java.lang.Math.E;

public class Utility {

    public static void main(String[] args) {

        System.out.println(PI); 
            // 3.141592653589793
        
        System.out.println(E); 
            // 2.718281828459045
    }
}

Impact

Be aware that you dump potentialy large classes into your namespace.
 
/**
 * Import static
 * 
 * Dumping potentialy large classes into your namespace ...
 * might have a negative impact on readabilty and testability
*/

package com.minte9.effective.import_static;

import static java.lang.Math.*; // Look Here

public class Impact {

    public static void main(String[] args) {

        System.out.println(PI); 
            // 3.141592653589793
        
        System.out.println(E); 
            // 2.718281828459045
    }
}

Questions     github Effective
Enums
        A B C D E F
🔔
1/1