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

后端 未结 5 663
孤街浪徒
孤街浪徒 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:23

    How about a static helper class that holds your common functions, call them from your enum methods.

    In regards to your comment about toString().

    public enum MyEnum{
    
    ONE("one");
    
    public MyEnum(String m_Name){
      this.m_Name = m_Name;
    }
    public String toString(){
      return m_Name;
    }
    String m_Name;
    }
    

提交回复
热议问题