Static Import 用法之 Constant Utility Class

来源:互联网 发布:文泰刻绘软件下载 编辑:程序博客网 时间:2024/06/05 02:04


// Constant utility class
package com.effectivejava.science;


public class PhysicalConstants {

private PhysicalConstants() { } // Prevents instantiation

public static final double AVOGADROS_NUMBER = 6.02214199e23;

public static final double BOLTZMANN_CONSTANT = 1.3806503e-23;

public static final double ELECTRON_MASS = 9.10938188e-31;

}


// Use of static import to avoid qualifying constants
import static com.effectivejava.science.PhysicalConstants.*;


public class Test {

double atoms(double mols) {

return AVOGADROS_NUMBER * mols;

}
...

// Many more uses of PhysicalConstants justify static import

}

原创粉丝点击