Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set prefix (e.g. "m") to remove in Android Studio's Alt-Insert getter/setter?

I make most of my member variables start with the letter "m", for example mId or mIsSomething. When I use the keyboard shortcut to add getters/setters, I end up with:

public void setmId() {}

but I want:

public void getId() {}

How do I set a prefix for it to remove when creating the getter/setter?

like image 439
Don Rhummy Avatar asked Oct 29 '14 04:10

Don Rhummy


People also ask

What is getter and setter in Android?

Getters and setters are used to protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value.

How do you get a getter setter in Kotlin?

In Kotlin, setter is used to set the value of any variable and getter is used to get the value. Getters and Setters are auto-generated in the code. Let's define a property 'name', in a class, 'Company'. The data type of 'name' is String and we shall initialize it with some default value.


2 Answers

I found the solution:

Go to File -> Other Settings -> Default Settings

In the search box, type "prefix".

On the right, select the tab "Code Generation".

In the "prefix" box, type m (or whatever your prefix is)

like image 62
Don Rhummy Avatar answered Oct 21 '22 19:10

Don Rhummy


  1. Open Default Settings (File -> Other Settings -> Default Settings)
  2. Go to Editor -> Java -> Code Generation
  3. Select Prefer longer names
  4. Enter m in Field as prefix

enter image description here

like image 46
Igor Avatar answered Oct 21 '22 19:10

Igor