美文网首页
# AndroidStudio代码块的自动补全

# AndroidStudio代码块的自动补全

作者: 散仙_云折 | 来源:发表于2020-11-09 10:00 被阅读0次

    AndroidStudio代码块的自动补全

    settings --> Editor --> Live Templates

    * 定义一个私有的内部类,在第一次用这个嵌套类时,会创建一个实例。而类型为SingletonHolder的类,
    * 只有在Singleton.getInstance()中调用,由于私有的属性,他人无法使用SingleHolder,
    * 不调用Singleton.getInstance()就不会创建实例。
    * 优点:达到了lazy loading的效果,即按需创建实例。
    */
    

    private class(){}
    private static class SingletonHolder {
    public static class instance = new class();
    }

    public static class ins() {
    return SingletonHolder.instance;
    }
    ​</pre>

    private static final String TAG = "class";
    private class(){}
    /**

    • 定义一个私有的内部类,在第一次用这个嵌套类时,会创建一个实例。而类型为SingletonHolder的类,
    • 只有在Singleton.getInstance()中调用,由于私有的属性,他人无法使用SingleHolder,
    • 不调用Singleton.getInstance()就不会创建实例。
    • 优点:达到了lazy loading的效果,即按需创建实例。
      */
      private static class SingletonHolder {
      public static class instance = new class();
      }

    public static class ins() {
    return SingletonHolder.instance;
    }

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="java" cid="n13" mdtype="fences" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; position: relative !important;"> private static final String TAG = "class";
    private class() {}
    public volatile static class myInstance;
    public static class ins() {
    if (myInstance == null) {
    synchronized (class.class) {
    if (myInstance == null) {
    myInstance = new class();
    }
    }
    }
    return myInstance;
    }
    ​</pre>

    避免重复造轮子贴出来俩:

    [图片上传失败...(image-25cb22-1600260779098)]

    还需要你选择一下选择一下name的表述才行 比如我是想要class 那就拿classname()吧,ok了 就这样了

    天真了吧!这样生成出来的肯定不是你想要自动补齐类名的东西!!!

    你以为这样就完了?

    img

    相关文章

      网友评论

          本文标题:# AndroidStudio代码块的自动补全

          本文链接:https://www.haomeiwen.com/subject/ozghyktx.html