Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactor variable access in Android Studio? (Delegate to method)

I have a variable in a class:

public final class Things {
    public static final Thing OBJECT = new Thing();
}

I access it in various places with:

Things.OBJECT.someCoolMethod();

I want to use it like this:

Things.getObject().someCoolMethod();

How can I acheive this automatically with refactoring? I dont want to have to go through each class accessing it manually (Its a huge project)

Thanks for your help!

like image 387
zoltish Avatar asked May 30 '26 02:05

zoltish


1 Answers

After some digging I found a solution. Hope that this will help other adventurers further down the road too.

Right click variable > Refactor > Encapsulate Fields... > Getter

like image 105
zoltish Avatar answered May 31 '26 17:05

zoltish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!