I've read many answers here confirming my (quite obvious) opinions about using enums instead of String
objects when dealing with a small, closed sets of values.
But lately I've noticed a couple of examples in the Java API where the opposite choice has been made. I can only remember this one right now
public RandomAccessFile(File file, String mode)
where mode
parameter can only be r
, rw
, rws
or rwd
. Otherwise, an IllegalArgumentException
exception will be thrown.
The only reason I can think of is that such method could be previous to enum introduction in Java language, am I right? If that's true, are there situations today where chosing a String instead of an enum could make any sense for a closed set?