📄 singlespoon.java
字号:
package singleton;
public class SingleSpoon {
private Soup soupLastUsedWith;
private static SingleSpoon theSpoon;
private static boolean theSpoonIsAvailable = true;
private SingleSpoon() {}
public static SingleSpoon getTheSpoon() {
if (theSpoonIsAvailable) {
if (theSpoon == null){
theSpoon = new SingleSpoon();
}
theSpoonIsAvailable = false;
return theSpoon;
}else {
//spoon not available, could throw error or return null (as shown)
return null;
}
}
public String toString() {
return "Behold the glorious single spoon!";
}
public static void returnTheSpoon() {
theSpoon.cleanSpoon();
theSpoonIsAvailable = true;
}
public Soup getSoupLastUsedWith() { return this.soupLastUsedWith; }
public void setSoupLastUsedWith(Soup soup) { this.soupLastUsedWith = soup; }
public void cleanSpoon() { this.setSoupLastUsedWith(null); }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -