IntelliJ IDEA 14.1.0 Help

Convert Anonymous to Inner

The Convert Anonymous to Inner refactoring allows you to convert an anonymous class into a named inner class.


Before After
public class Class { rface method() { nt i = 0; new Interface() { lic int publicMethod() { urn i;}
public class Class { rface method() { nt i = 0; new MyInterfaceClass(i); InterfaceClass implements Interface { al int i; terfaceClass(int i) { = i; publicMethod() { i;

To inline a constructor

  1. Place the cursor within the anonymous class to be refactored.
  2. On the main menu, or on the context menu of the selection, choose Refactor | Convert Anonymous To Inner. The Convert Anonymous To Inner dialog opens.
  3. In the Class name field specify the name for the new inner class.
  4. In the Constructor parameters area select the variables, that will be used as parameters to the inner class constructor.
  5. Click OK to create the inner class.

See Also

Last modified: 24 March 2015
comments powered by Disqus