java - Is there a way to let the enum return the value without method -


if enum:

public enum planet {     mercury (3.303e+23),     neptune (1.024e+26);      private final double mass;   // in kilograms      planet(double mass) {         this.mass = mass;     }     private double mass() {          return mass;      } } 

i can access values like

planet.mercury.mass(); 

is there chance define enum "double" , let

planet.mercury; 

return double?

anyway i'm interested in appearance of call ensure code readability.

no. not possible java representation of enums. find planet.mercury.mass() more readable.

the thing comes mind increasing readability making mass public final instead of private final , refer planet.mercury.mass give second thoughts.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -