Turning public items into private items - Java, IntelliJ

Viewed 4656

I just wonder if there is a way to make public items (fields, methods) private with a simple button or something

public Group wQ;
public Group wA1;
public Group wA2;
public Group wA3;
public Group wG1;
public Group wG2;
public Group wG3;
public Group wS1;
public Group wS2;
public Group wB1;
public Group wB2;

For example make all these fields private in one step, without replacing public with private. I use IntelliJ IDEA btw.

3 Answers

In addition to @RAnders00's answer, there's another way that lets IntelliJ do it automatically without generating setters/getters whilst also checking if you would break code:

Rightclick on the class or package → Analyze → Run Inspection by Name → Declaration access can be weaker

IntelliJ will search your class for members that can have a reduced visiblity based on usage. After scanning you can have it updated automatically.

Related