选项1:
public class WidgetStatics {
public static final String FIZZ = "fizz";
public static final String BUZZ = "buzz";
}
进而:
import com.me.myorg.myapp.WidgetStatics
public class Thing1 {
public void doSomething() {
String x = getValueFromUser();
if(x.equals(WidgetStatics.FIZZ))
// ...
}
}
选项#2:
public interface WidgetStatics {
public static final String FIZZ = "fizz";
public static final String BUZZ = "buzz";
// ...
}
进而:
public class Thing2 implements WidgetStatics {
public void doSomething() {
String x = getValueFromUser();
if(x.equals(FIZZ))
// ...
}
}
我的问题:
- 一种选择是否比另一种更高效?哪个会导致更多的努力
ClassLoader
:导入或实施? - 是否存在一种方法比另一种方法更可取/更清洁的特定用例?