单例模式(一)

偶然间写了一个单例

public class TextView extends View {
private Context context;
private static TextView textView;

public TextView(Context context) {
super(context);
this.context = context;
}

public TextView getInstance() {
if (textView == null) {
synchronized (TextView.class) {
if (textView == null) {
textView = new TextView(context);
}
}
}
return textView;
}

}
posted @ 2016-01-21 15:27  Pace千雨  阅读(123)  评论(0编辑  收藏  举报