// Constant interface antipattern - do not use! publicinterfacePhysicalConstants{// Avogadro's number (1/mol)staticfinaldoubleAVOGADROS_NUMBER=6.022_140_857e23;// Boltzmann constant (J/K) staticfinaldoubleBOLTZMANN_CONSTANT=1.380_648_52e-23;// Mass of the electron (kg) staticfinaldoubleELECTRON_MASS=9.109_383_56e-31;}
위 처럼 정의된 상수 는 implementation detail 이다. Interface 에 정의되어 외부에 노출될 필요가 없다. 더 중요하게는 이런식의 인터페이스를 구현해 버린 클래스가 등장하면 아주 상태가 곤란해진다. 빠지면 섭섭하게... Java Platform 에도 이런 예시가 있다. java.io.ObjectStreamConstants
Use interfaces only to define types 라는 격언은 이번 Item 에서 다룬 constant interface 와 같은 이제는 모든 자바 개발자가 체화되어 알고 있다고 여겨지는 원칙에도 적용이 되지만 앞선 Item 20, 21 에서 다룬 default method 를 통한 Interface 에 구현을 담는 행위에도 해당 되는 말이다.