-
Enhancement
-
Resolution: Fixed
-
P4
-
1.3.0, 5.0
-
tiger
-
generic
-
generic
Name: gh8910 Date: 02/18/2002
Many classes and interfaces defines constants as static final values
such as RED, BLUE, GREEN, etc.
Programmers often want to have easy access to these constants so
they can name then as simply RED, BLUE, etc.
At the moment there is no direct support for doing this in the
Java language. Unfortunately a rather dangerous idiom has emerged
to work around this limitation. Programmers define the constants in
interfaces and then those classes that want easy access to the
constants say that they implement the interface. This pulls the
constants into scope.
Unfortunately this idiom doesn't simply affect the implementation
of the class. It also affects its API. So for implementation
convenience programmers are tempted to add implementation features
into their class API.
It seems better to solve this at the Java language level by adding
an explicit mechanism to import statics from a class or interface.
This might take the general form:
import static x.y.Z.*;
which would mean import all static constants from the class x.y.Z.
======================================================================
Many classes and interfaces defines constants as static final values
such as RED, BLUE, GREEN, etc.
Programmers often want to have easy access to these constants so
they can name then as simply RED, BLUE, etc.
At the moment there is no direct support for doing this in the
Java language. Unfortunately a rather dangerous idiom has emerged
to work around this limitation. Programmers define the constants in
interfaces and then those classes that want easy access to the
constants say that they implement the interface. This pulls the
constants into scope.
Unfortunately this idiom doesn't simply affect the implementation
of the class. It also affects its API. So for implementation
convenience programmers are tempted to add implementation features
into their class API.
It seems better to solve this at the Java language level by adding
an explicit mechanism to import statics from a class or interface.
This might take the general form:
import static x.y.Z.*;
which would mean import all static constants from the class x.y.Z.
======================================================================
- duplicates
-
JDK-4460292 Easy way to use constants in a class without qualifying each use
- Closed
-
JDK-4639380 support for importing constants
- Closed