枚举对象.equals(枚举对象)是可以的。因为枚举类是单例。
@Test
public void testEnum() {
boolean b = BookingType.DailyDeskReservation.name().equals("DailyDeskReservation");
Assert.assertTrue(b);
boolean a = BookingType.DailyDeskReservation.equals("DailyDeskReservation");
Assert.assertFalse(a);
boolean c = BookingType.DailyDeskReservation.equals(BookingType.DailyDeskReservation);
Assert.assertTrue(c);
boolean d = "DailyDeskReservation".equals(BookingType.DailyDeskReservation);
Assert.assertFalse(d);
}
public enum BookingType {
ConferenceRoomReservation,
CommonSpaceReservation,
DailyDeskReservation,
}