Switch over type in java

后端 未结 8 1143
执念已碎
执念已碎 2020-12-02 14:23

Before I start, I know there are a bunch of answers to this question that suggest alternate approaches. I\'m looking for assistance to this particular approach as to whethe

8条回答
  •  难免孤独
    2020-12-02 15:16

    Java currently has a draft to support this. See here. The syntax looks like this

    switch (obj) {
        case Integer i: handleI(i); break;
        case Byte b:    handleB(b); break;
        case Long l:    handleL(l); break;
        case Double d:  handleD(d); break;
        case String s:  handleS(s); break
        default:        handle(obj);
    }
    

提交回复
热议问题