In java, What does such enum type compile to?

前端 未结 3 768
执笔经年
执笔经年 2020-12-14 10:35

Below is the code that defines enum type.

enum Company{
    EBAY(30), PAYPAL(10), GOOGLE(15), YAHOO(20), ATT(25);
    private int value;

    private Company         


        
3条回答
  •  鱼传尺愫
    2020-12-14 11:08

    Functionally, yes. Literally no (you can't explicitly sub-class Enum for one thing). enum(s) have a toString. And your enum isn't valid code (you can't call super()) and getValue needs a return type.

    enum Company{
        EBAY(30), PAYPAL(10), GOOGLE(15), YAHOO(20), ATT(25);
        private int value;
    
        private Company(int value){
            this.value = value;
        }
    
        public int getValue(){
            return value;
        }
    }
    

提交回复
热议问题