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?
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.
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.
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)
File -> Other Settings -> Default Settings
)Editor -> Java -> Code Generation
Prefer longer names
m
in Field as prefixIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With