How java specifies the behavior of enumerations
Description
1. Enumerations can not only be used to represent constants, but also sometimes write some simple computational logic in enumerations.
2. You can use abstract methods to define the behavior required by each enumeration.
Example
Package com.tea.modules.java8.enums; import lombok.Getter; / * com.tea.modules.java8.enums
* operator enumeration * * @ author jaymin * @ since 2021-6-10 * / @ Getterpublic enum OperationEnum {/ * plus * / PLUS ("+") {@ Override public double apply (double x, double y) {return x + y }}, / * * minus * / MINUS ("-") {@ Override public double apply (double x, double y) {return x-y }}, / * multiply * / TIMES ("*") {@ Override public double apply (double x, double y) {return x * y }}, / * except * / DIVIDE ("/") {@ Override public double apply (double x, double y) {return x / y;}}; / * * operator * / private final String symbol; OperationEnum (String symbol) {this.symbol = symbol } public abstract double apply (double x, double y);} above is all the content of the article "how java specifies the behavior of enumerations". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.