Define a few specific date formatters as members of an enum in Java
问题 I need to track a few formats (DateTimeFormatter objects) for repeated use in my app. ➥ How to represent these formatter objects by using a Java enum? 回答1: tl;dr Yes. FormatDateOnly.DD_MM_YYYY.getFormatter() Details Yes, you can easily store some DateTimeFormatter objects in an enum. The slick enum facility in Java is quite powerful and flexible. Basically, an enum in Java is almost a normal Java class. Your enum can have member variables to store objects internally. Your enum can have a