Using Integer in Switch Statement

后端 未结 6 1788
心在旅途
心在旅途 2020-12-10 15:05

For various business reasons I want to hold some static IDs in one of my classes. They were originally int but I wanted to change them to Integer s

6条回答
  •  天涯浪人
    2020-12-10 15:38

    because I was looking at this...

    The accepted answer says that:

    switch can only work with primitives, enum values and (since Java 7) strings

    However,

    14.11 The switch Statement

    outlines the JavaSE7 documentation for switch that shows:

    The type of the Expression must be char, byte, short, int, Character, Byte, Short, Integer, String, or an enum type (§8.9), or a compile-time error occurs.

    I just wanted to clarify for future surfers.

提交回复
热议问题