单例模式(一)
偶然間寫了一個單例
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;
}
}
轉載于:https://www.cnblogs.com/520-1314/p/5148437.html
總結
- 上一篇: WeUI 为微信 Web 服务量身设计-
- 下一篇: 三天100元从零开始搭建Hadoop集群