简体   繁体   English

在Android Studio中生成延迟加载程序

[英]Generating lazy loaders in Android Studio

I need to instantiate a lot of fields in a "lazy" way. 我需要以“惰性”方式实例化许多字段。 Is there any plugin for Android Studio that could generate getters with lazy instantiation and make my life easier? Android Studio是否有任何插件可以通过延迟实例化生成吸气剂并使我的生活更轻松? I need my getter to look like this: 我需要我的吸气剂看起来像这样:

public String getName() {
    if(mName == null){
        mName = "Some value here"
    }
return mName;
}

Go to the class you want to implement the getters and setters, hit ctrl + insert and a dialog will appear, click "Getter" or "Setter" and choose the variables you want to implement getters/setters for. 转到要实现getter和setter的类,按Ctrl + Insert,将出现一个对话框,单击“ Getter”或“ Setter”,然后选择要实现getter / setter的变量。

This also works for Override and Implement methods from classes you extend. 这也适用于您扩展的类中的Override和Implement方法。

Hope this helps, happy coding. 希望对您有所帮助,祝您编程愉快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM