This is from Effective Java
Programs that use the int enum pattern are brittle. Because int enums are
compile-time constants, they are compiled into the clients that use them.
Can some one explain why the int enum pattern is called compiled type constant and what is meant by compiled into the clients?
Here s’ an example of such a constant :
public static final int APPLE_FUJI = 0;
Suppose you have two files:
Compile them both, run
java Barand it will print out 1.Now change Foo.java so that
SOMETHINGis 2, and recompile just Foo.java. Rerunjava Barand it will still print 1. The constant value will be copied to every piece of code that uses it, rather than asking for the value fromFooat execution time.In practice, if you recompile everything any time anything changes, this isn’t a problem.