0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シングルトンでクロージャなカウンタ

Last updated at Posted at 2013-06-07

これもずっと使いまわしているクラス。
private なクラスとして下の方に、こそっと追加して使ったりしてます。

シングルトンって?
クロージャって?

って人への一例として登録します。

java.count
class cnt
{
	static cnt Cnt;
	int counter = 0;

	static cnt getInstance(){
		if(null == Cnt) {
			Cnt = new cnt();
		}
		return Cnt;
	}
	void add() {
		counter++;
	}
	int get() {
		return counter;
	}
	void reset() {
		counter = 0;
	}
}
0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?