我試圖做一些二進制對象位與比較:不兼容的錯誤類型Java中
private int selectedButtons = 0x00;
private static final int ABSENCE_BUTTON_SELECTED = 0x01;
private static final int SICKNESS_BUTTON_SELECTED = 0x02;
private static final int LATENESS_BUTTON_SELECTED = 0x04;
這裏是比較:
boolean absenceButtonEnabled = selectedButtons & ABSENCE_BUTTON_SELECTED;
但我得到這個錯誤:
Error:(167, 56) error: incompatible types
required: boolean
found: int
任何想法?
請考慮* Effective Java 2nd Ed的建議*第32項:「使用EnumSet而不是位域」。 –