Wrap return value

Last modified: 29 November 2022

Required plugin: Additional Java Refactorings (installed and enabled)

The Wrap Return Value refactoring allows you to select a method, and either create a wrapper class for its return values, or use an existing, compatible wrapper class. All returns from the method selected will be appropriately wrapped, and all calls to the method will have their returns unwrapped.

Wrapping a method's returns are useful, if your design changes in such a way that you want a method to return more information than originally planned. After wrapping, the wrapper class can be extended, allowing more data to be returned from the method. Also, it is common to wrap primitive return values, thus allowing interface and implementation to be decoupled as needed.