How to automatically generate getters and setters in Android Studio

后端 未结 15 1143
太阳男子
太阳男子 2020-12-02 04:15

Is there a shortcut in Android Studio for automatically generating the getters and setters in a given class?

相关标签:
15条回答
  • 2020-12-02 05:15
    • create the variable
    • right click
    • select "Generate" and then select "Getter and Setter" option

    0 讨论(0)
  • 2020-12-02 05:15

    Just in case someone is working with Eclipse

    Windows 8.1 OS | Eclipse Idle Luna

    Declare top level variable private String username Eclipse kindly generate a warning on the left of your screen click that warning and couple of suggestions show up, then select generate.enter image description here

    0 讨论(0)
  • 2020-12-02 05:21

    As noted here, you can also customise the getter/setter generation to take prefixes and suffixes (e.g. m for instance variables) into account. Go to File->Settings and expand Code Style, select Java, and add your prefixes/suffixes under the Code Generation tab.

    0 讨论(0)
提交回复
热议问题