⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singlespoon.java

📁 仅学习使用
💻 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 + -