Why are all fields in an interface implicitly static and final?

peakit picture peakit · Oct 3, 2009 · Viewed 94.6k times · Source

I am just trying to understand why all fields defined in an Interface are implicitly static and final. The idea of keeping fields static makes sense to me as you can't have objects of an interface but why they are final (implicitly)?

Any one knows why Java designers went with making the fields in an interface static and final?

Answer

Adriaan Koster picture Adriaan Koster · Oct 3, 2009

An interface can't have behavior or state because it is intended to specify only an interaction contract, no implementation details. 'No behavior' is enforced by not allowing method/constructor bodies or static/instance initializing blocks. 'No state' is enforced by only allowing static final fields. Therefore, the class can have a state (static state), but the instance state is not inferred by the interface.

BTW : A constant in Java is defined by a static final field (and by convention the name uses UPPER_CASE_AND_UNDERSCORES).