在我的聊天应用程序中,我有一个枚举:
enum ContactRelationType {
Friend,
Familiar,
Ignored,
Unknown,
Guild,
Officers,
Academy,
Community,
System
}
Run Code Online (Sandbox Code Playgroud)
ContactRelationType值的一半是房间(公会,官员,学院,社区,系统).我需要知道的是价值空间与否.
我知道三种方法:
首先:
enum ContactRelationType {
Friend,
Familiar,
Ignored,
Unknown,
Guild,
Officers,
Academy,
Community,
System;
public boolean isRoom() {
return this == Guild ||
this == Officers ||
this == Academy ||
this == Community ||
this == System;
}
}
Run Code Online (Sandbox Code Playgroud)
它看起来很难看,IDEA告诉我"过于复杂的布尔表达式",它就是.
第二:
enum ContactRelationType {
Friend,
Familiar,
Ignored,
Unknown,
Guild,
Officers,
Academy,
Community,
System;
public boolean isRoom() {
switch (this) {
case Guild:
case Officers: …Run Code Online (Sandbox Code Playgroud) 据我所理解:
window.addEventListener('storage', function(event){
...
}, false);
Run Code Online (Sandbox Code Playgroud)
是对localStorage和sessionStorage事件的订阅。我只能订阅localStorage事件吗?
谢谢。