Packages
Enumerations
Work with static imports
How to work with static imports
How to code a static import statement import static murach.business.ShippingType.*; The code above when a static import is used ShippingType ground = UPS_GROUND; System.out.println("toString: " + ground.toString() + "\n");
How to enhance an enumeration and work with static imports
- All enumerations inherit the java.lang.Object and java.lang.Enum classes. They can use or override the methods of those classes or add new methods.
- By default, the toString method of an enumeration constant returns the same string as the name method.
- You can use a static import to import all of the constants of an enumeration or all of the static fields and methods of a class.
- When you use a static import, you don't need to qualify the constant, field, or method with the name of the enumeration or class.