0
点赞
收藏
分享

微信扫一扫

​.NET基础入门​

small_Sun 2024-04-26 阅读 18

目录

背景说明

代码实现

 手写笔记


背景说明

代码实现

class Singleton{
 private Singleton(){

 }
 private static Singleton instance;
 public static Singleton GetInstance(){
     if(instance==null)
     {
         Singleton.instance = new Singleton();
     }
     return instance;
 }
}
public class Test {
    public static void main(String[] args){
        Singleton S1 = Singleton.GetInstance();
        Singleton S2 = Singleton.GetInstance();

        if(S1.equals(S2))
        {
            System.out.println("两对象相同,成功实现!");
        }
        else{
            System.out.println("两对象不同,大失败!!");
        }
    }

}

 手写笔记

今天的分享到这里就结束啦~~希望能帮到您 

举报

相关推荐

0 条评论