Submitted On 03-APR-1998
MiguelM
Interfaces that define static final constants may
miss type-safety, but what they really miss is
convenience, and avoidance of duplication. I love
using enumerated variables in C++, and (unlike
most of the powerful features of C++) they don't
bring a lot of baggage to the language.
Although the convenience of enums is a bug plus,
I especially like the way enums avoid duplication
problems. This is a good example of using a
language feature to eliminate a class of bugs.
Their exclusion from java is a (rare) step
backwards.
Incidentally, interfaces with constants don't
really give us the functionality of enums, they
give us the functionality of include files. (Which
is great.) I still miss enums when I work with
java.
Submitted On 12-JUN-1998
paulgear
P.S. Why is this closed? I want to vote for it! :-)
Submitted On 12-JUN-1998
paulgear
Convenience is certainly a factor, but type safety is far more important. I
find it very hard to accept that type safety isn't a big enough win to warrant
changing the language. Java provides type safety just about everywhere else -
lack of enum is just plain inconsistent.
This sort of feature should be able to be introduced with minimal impact -
surely it would not affect the VM...??
Submitted On 01-JUL-1998
cjmcgee
I want to vote for it too
Submitted On 07-OCT-1998
bpflanz
Not having enums is intolerable.
My comments on functions that take "int"s now have
to list all the acceptable values.
As already mentioned, enums provide compile-time
type checking - checking for correct values at
runtime brings an overhead with it, and also
allows only two choices - either you convert the
wrong value to the "closest" acceptable value,
so doing something which may have been entirely
undesired by the person who used the "int", or
you throw an exception - absolutely unacceptable,
for what is basically a kind of typo!
Secondly, enums make the meaning of a function
much clearer (especially if the return is an enum).
Shame on you, Sun, for not adding enums!
Submitted On 12-NOV-1998
callas
james gosling's $.02 can be found at
http://www.javaworld.com/javaworld/jw-06-1998/jw-06-letters.html
Submitted On 22-JUL-1999
headland
One uses classes to get type-safe enumeration of
values in an object-oriented programming language,
not ints and not C-like enums.
Submitted On 05-NOV-1999
S115
I always thought one of the big advantages of JAVA is type safty. Why not in
this case ?
Submitted On 16-DEC-1999
bradgreen
I want to vote for this, also. The performance of Java is slow enough without
having to declare heavy-weight classes just to return an enumerated value.
Submitted On 21-MAR-2000
ashbyrich
The lack of enumerated types is truly infuriating. I think it rather folish to have closed the voting on it, too.
Here is a potential solution:
public class Car
{
protected Car() {}
public static final Car FORD=new Car();
public static final Car VW=new Car();
public static final Car SAAB=new Car();
}
...apparently this works. I have yet to test it fully.
Source: http://www.javaworld.com/javatips/jw-javatip27.html
Submitted On 30-NOV-2000
jtappan
It is very unfortunate that they refuse to fix this. The
official line is that you should create a class with a
private constructor and public static member instances.
Enums (as implemented in C++) would be much easier to use.
Without them everyone (even the Sun programmers) ends up
using int constants, which makes the code more fragile.
Submitted On 29-DEC-2000
paulgear
Does anyone in Sun read these? Please reopen this bug!
Submitted On 19-FEB-2001
whitmad
Please review and add this facility. Almost everyone I know
considers this a flaw in the language definition and would
like to see enumeration constants. How hard cane it be to
do?
Submitted On 05-MAR-2001
jlmoya
I can't believe there is no enum support. As it is, it's a very clumsy way to emulate an enum.
Submitted On 23-JUL-2001
thomas.sievers@gmx.de
Using static final int constants is a ridiculous
alternative to using enum types. A method setDay(int) is
simply not logical (it must be setDay(dayOfWeek), where
dayOfWeek is {monday,...,sunday}). Furthermore this way a
static typecheck is not possible, so reliability suffers
significantly. The statement '...they aren't a big enough
win' states quite a portion of ignorance of developing
reliable software systems; for some C hacking int constants
might actually be enough. And finally, defining classes
with these constants and get/set method induces quite a lot
of unnecessary overhead to the programmer, which itselfs
might induce bugs.
Submitted On 23-AUG-2001
MiguelM
Classes like this:
public class Car
{
protected Car() {}
public static final Car FORD=new Car();
public static final Car VW=new Car();
public static final Car SAAB=new Car();
}
solve many problems, but I want to be able to use enumerations in switch statements. I can't say
public void doSomething(Car theCar)
{
switch (theCar)
{
...
because the switch requires an integer. And if I give an integer value to each enumaration, I can't say
...
case FORD.intValue:
because this requires a constant. It doesn't even work if I make intValue final. I want integral enumerations
with type safety.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|