How to add common methods for a few Java enums? (abstract class ancestor?)

后端 未结 5 661
孤街浪徒
孤街浪徒 2021-01-04 07:01

I have a few Java enums as such

public enum Aggregation
{
    MORTGAGE( \"Mortgage\" ),
    POOLS( \"Pools\" ),
    PORTFOLIO( \"Portfolio\" );

    private         


        
5条回答
  •  隐瞒了意图╮
    2021-01-04 07:24

    just define your common behviur in the First class:

    public class First {
     public String name() {
      return "my name";
     }
     ...
    }
    

    and than extend it in each class:

    public SecondClass extends First {
     ...
    }
    

提交回复
热议问题