第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在Java中開啟Enum

在Java中開啟Enum

溫溫醬 2019-11-14 09:39:00
為什么不能打開Java枚舉?看起來很簡單,可以編寫一些方便的代碼。這個(gè)問題也適用于String。您可以打開char,但不能打開String...?
查看完整描述

3 回答

?
慕哥9229398

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊

實(shí)際上,您可以switch使用enums,但是直到Java 7才可以switch使用Strings。您可以考慮將Java enum的多態(tài)方法分派使用,而不是顯式switch。請注意,enums是Java中的對象,而不僅僅是ints的符號(hào),就像在C / C ++中一樣。您可以在enum類型上有一個(gè)方法,然后不用編寫a switch,只需調(diào)用該方法-一行代碼即可:完成!


enum MyEnum {

    SOME_ENUM_CONSTANT {

        @Override

        public void method() {

            System.out.println("first enum constant behavior!");

        }

    },

    ANOTHER_ENUM_CONSTANT {

        @Override

        public void method() {

            System.out.println("second enum constant behavior!");

        }

    }; // note the semi-colon after the final constant, not just a comma!

    public abstract void method(); // could also be in an interface that MyEnum implements

}


void aMethodSomewhere(final MyEnum e) {

    doSomeStuff();

    e.method(); // here is where the switch would be, now it's one line of code!

    doSomeOtherStuff();

}


查看完整回答
反對 回復(fù) 2019-11-14
  • 3 回答
  • 0 關(guān)注
  • 403 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)