java comparison of two enums
问题 Given the test code: @Test public void testEnumAreEqual() { for (var someEnum : SomeEnum.values()) { Assertions.assertTrue(EnumUtils.isValidEnum(OtherEnum.class, someEnum.name())); } for (var otherEnum : OtherEnum.values()) { Assertions.assertTrue(EnumUtils.isValidEnum(SomeEnum.class, otherEnum.name())); } } I want to check if two given enums are containing the same values. Is there maybe a more elegant way to do this? 回答1: Build a set of the names: Set<String> someEnumNames = Arrays.stream