IntelliJ IDEA
 
Get IntelliJ IDEA
You are viewing the documentation for an earlier version of IntelliJ IDEA.

Replace temp with Query

Last modified: 08 March 2021

The Replace Temp with Query refactoring lets you extract the variable's initializer expression into a method, and replace all references to the variable with the calls to the extracted method. The declaration of the variable will be removed and the query method can be used in other methods.

Instead of int size = getActualSize() and using size throughout the code, we just operate with getActualSize() method. Though the resulting code has more invocations, it is much cleaner and helps identify precisely where the bottlenecks in the code can appear.