单例模式(一)
偶然间写了一个单例
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;
}
}