So consider a function like this:
public void setTemperature(double newTemperatureValue, TemperatureUnit unit)
where TemperatureUnit is defined as:
public enum TemperatureUnit {celcius, kelvin, fahrenheit}
I would ideally like to get to is this:
setTemperature(23, celcius);
So ultimately I would like to omit the ‘TemperatureUnit.’ part that would normally precede the value of the enum, since in this way the function reads more like as if it was regular text.
Now I can of course do a static import to accomplish this, but I wonder if there are alternatives to that, hopefully while also keeping things clean. I have heard of people using an interface that declares them, but which is also considered bad practice.
Any suggestions?
Well, you’ve listed all 3 technical possibilities. Personally, I’d favor using the full name of the enum class but rename it to produce more natural sounding code: