简体   繁体   中英

IntelliJ Idea: Replace usages of constants by actual values in all classes in a package

In my Java project I was told to avoid the usage of integer and String constants in certain classes. Is there any shortcut in IntelliJ Idea to replace all usages of String and integer constants by their actual values? Something like "Extracting constants backwards". Because there are a lot of places to change and I wondered if there was some way to do it automatically.

Initial: Do you mean something like this: https://www.jetbrains.com/help/idea/extract-constant.html

Update: I will try with an example, I guess this is your case (sorry if i misunderstood again)

Lets say I have:

private static final String PAGE = "page";
private static final String LIMIT = "size";
private static final String SORT = "sort";

Then do a right click on the PAGE String: Refactor > Inline Field

在此处输入图像描述

and do the Refactor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM