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
Post a Comment