Eclipse 创建代码模板,单例模式

使用eclipse写单例模式时,往往要写很多相同的代码。可以使用模板进行简化。像在eclipse里写syso,会自动补全System.out.println();

eclipse 菜单栏依次进入:

Window->Preferences->Java->Editor->Templates->New 

创建一个饿汉单例模式模板,名字叫:single,内容如下。

private static volatile ${enclosing_type} instance = new ${enclosing_type}();
private ${enclosing_type}(){}
public static ${enclosing_type} getInstance(){
    return instance;
}

在 java 文件中输入:single,即可像输入syso一样,补全代码。

参考:http://www.fengyunxiao.cn

猜你喜欢

转载自blog.csdn.net/m0_37202351/article/details/82283999