---
title: "java编写单例模式Singleton"
author: "breakfalse"
date: "2014-03-16T00:59:56Z"
tags: []
categories: ["编程语言"]
slug: "java-singleton"
draft: false
lastmod: "2014-03-16T01:17:27Z"
id: 2031639
url: "https://breakfalse.iteye.com/blog/2031639"
---

package com.feipin.test;

/\**  
 * Title:设计一个单例模式  
 *  
 * Description:  
 *  
 * @version 1.0  
 \*/  
public class SingletonTest {  
 private static SingletonTest instance = null;  
 //注意这是private 只供内部调用  
 private SingletonTest(){}  
 //这里提供了一个供外部访问本class的静态方法，可以直接访问　　  
 public static SingletonTest getInstance() {  
  if (instance==null){  
   instance = new SingletonTest();  
  }  
  return instance ;  
 }  
}