Simple screenshot that explains the singleton invocation.
Here is the code:
/*
Some class,such as a config file,need to be only one.So we need to control the instance.
1,private the constructor and create only one instance in the class itself.
2,provide a method for the others to get the 'only one' instance.
*/
package kju.obj; import static kju.print.Printer.*;
public class SingletonDemo {
public static void main(String[] args) {
SingleConfig con01 = SingleConfig.getInstance();
SingleConfig con02 = SingleConfig.getInstance();
println("con01 color : " + con01.getColor());
println("con02 set color : ");
con02.setColor("Blue");
println("con01 color : " + con01.getColor());
/*
con01 color : Orange
con02 set color :
con01 color : Blue
*/
}
} class SingleConfig {
private String color = "Orange";
private static SingleConfig s = new SingleConfig(); private SingleConfig() {}
public static SingleConfig getInstance() {
return s;
} public void setColor(String color) {
this.color = color;
} public String getColor() {
return color;
}
}
And the corresponds the code above:
Simple screenshot that explains the singleton invocation.的更多相关文章
- Simple screenshot that explains the non-static invocation.
Here is the code: /* Instance invocation in the memory: */ package kju.obj; import static kju.print. ...
- recursive - simple screenshot but detail principle.
the code below demonstates the principle of the'recursive-call' that the programing beginner may be ...
- Book Contents Reviews Notes Errata Articles Talks Downloads Resources Code Formatter Cover of C# in Depth Order now (3rd edition) Implementing the Singleton Pattern in C#
原文链接地址: http://csharpindepth.com/Articles/General/Singleton.aspx#unsafe Implementing the Singleton P ...
- c# 几种singleton 实现
http://csharpindepth.com/Articles/General/Singleton.aspx#introduction 4th在线看 https://www.manning.com ...
- Implementing the Singleton Pattern in C#
Table of contents (for linking purposes...) Introduction Non-thread-safe version Simple thread safet ...
- Burp Suite教程(英文版)
In this article, we are going to see another powerful framework that is used widely in pen-testing. ...
- Multithreading annd Grand Central Dispatch on ios for Beginners Tutorial-多线程和GCD的入门教程
原文链接:Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial Have you ever written a ...
- [学习笔记]设计模式之Facade
写在前面 为方便读者,本文已添加至索引: 设计模式 学习笔记索引 Facade(外观)模式定义了一个高层接口,它能为子系统中的一组接口提供一个一致的界面,从而使得这一子系统更加容易使用.欢迎回到时の魔 ...
- 《PHP 设计模式》翻译完毕
翻译进度请见:https://laravel-china.org/docs/php-design-patterns/2018?mode=sections 设计模式不仅代表着更快开发健壮软件的有用方法, ...
随机推荐
- 李洪强iOS开发之-环信01_iOS SDK 前的准备工作
李洪强iOS开发之-环信01_iOS SDK 前的准备工作 1.1_注册环信开发者账号并创建后台应用 详细步骤: 注册并创建应用 注册环信开发者账号 第 1 步:在环信官网上点击“即时通讯云”,并点 ...
- js中常用framesetiframe页面跳转传参方法实例大全
logf的空间
- 使用HttpServletRequestWrapper在filter修改request参数
javax.servlet.ServletRequest中的 Map<String, String[]> parameterMap = request.getParameterMap(); ...
- haskell模块(modules)
装载模块 Haskell 中的模块是含有一组相关的函数,类型和类型类的组合.而 Haskell 进程的本质便是从主模块中引用其它模块并调用其中的函数来执行操作.这样可以把代码分成多块,只要一个模块足够 ...
- Android应用--新浪微博客户端新特性滚动视图和启动界面实现
新浪微博客户端新特性滚动视图和启动界面实现 2013年8月20日新浪微博客户端开发之启动界面实现 前言: 使用过新浪微博客户端的童鞋都清楚,客户端每一次升级之后第一次启动界面就会有新特性的介绍,用户通 ...
- 并行HASH JOIN小表广播问题
SQL语句: SELECT /*+parallel(t1 16)*/ T1.DATA_DATE, T1.ACCT_NO, T1.ACCT_ORD, T1.ACCT_NO_PK, T1.ACCT_BAL ...
- 未能导入activex控件,请确保它正确注册"的完美解决方案
这个错误“未能导入activex控件,请确保它正确注册”昨天下午让我和我同事花费了3个小时来调试这个错误,在使用VS2010的winfrom编程时加入com组件的时候,报这个错误(以一个客户的机器上) ...
- [JIT_APP]Java基础知识总结
一.Java语言的基础知识 1. 开发Java语言的公司 美国Sun(Sum Microsystems)公司开发. 2.Java的3个版本 J2SE(Java2 Standard Edition) ...
- 【转】SVN linux命令及 windows相关操作(一)
从以下博客转载和整理: http://www.cnblogs.com/richcem/archive/2011/01/08/1930823.html http://blog.wpjam.com/m/t ...
- ural 1333 化平面为点计算覆盖率
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1333 #include<cstdio> #include<cstrin ...