Java8第六章-继承和多态.pptVIP

  • 3
  • 0
  • 约1.31万字
  • 约 41页
  • 2017-06-03 发布于四川
  • 举报
* * * * * * * * 4单态设计模式:某个类只能存在一个对象实例,并且该类只提供一个 取得其对象实例的方法。singleton public class TestSingle{//形式一 private static final TestSingle onlyone=new TestSingle(); //前面加private static final修饰后只能产生一个对象 private TestSingle(){ //不能在类的外部new但在类的内部可以 } public static TestSingle getTestSingle(){ return onlyone;//外面只能通过方法调用获得一个对象 } } public class Singleton { // 形式二 private static Singleton instance = null; public static synchronized Singleton getInstance() { // 这个方法比上面有所改进,不用每次都进行生成对象,只是第一次 // 使用时生成实例,提高了效率! if (instance==null){ instance=new Sing

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档