Java enum valueOf() with multiple values?

前端 未结 6 819
庸人自扰
庸人自扰 2020-12-07 16:34

I have a problem in Java using Enums. I have read the documentation about assigning value parameters to Enums. But, my question is what about multiple values, is it possible

6条回答
  •  借酒劲吻你
    2020-12-07 17:16

    In short, no.

    The parameter for the valueOf() method must be only the String of the enum constant type. So it cannot vary, or lookup possible values. See the JavaDoc.

    You need to write your own utility method to return the proper enum type for the given values.

提交回复
热议问题