How to get all enum values in Java?

后端 未结 7 1593
独厮守ぢ
独厮守ぢ 2020-12-04 17:06

I came across this problem that I without knowing the actual enum type I need to iterate its possible values.

if (value instanceof Enum){
   Enu         


        
相关标签:
7条回答
  • 2020-12-04 18:01

    Here, Role is an enum which contains the following values [ADMIN, USER, OTHER].

    List<Role> roleList = Arrays.asList(Role.values());
    roleList.forEach(role -> {
        System.out.println(role);
        });
    
    0 讨论(0)
提交回复
热议问题