<html><head><link rel="canonical" href="https://www.jetbrains.com/help/idea/inline.html.md/" data-react-helmet="true"/></head><body># Inline

&gt; **TL;DR**
&gt; `Refactor | Inline`
&gt;
&gt;
&gt;
&gt; `Ctrl+Alt+N` (Windows), `⌘ ⌥ N` (macOS), `⌘ ⌥ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ N` (macOS System Shortcuts), `Ctrl+Alt+N` (XWin), `Ctrl+Alt+N` (GNOME), `Ctrl+Alt+N` (KDE), `Ctrl+Alt+N` (Emacs), `Ctrl+Alt+N` (Sublime Text), `⌘ ⌥ N` (Sublime Text (macOS)), `Ctrl+Alt+N` (NetBeans), `Ctrl+R, I` (Visual Studio), `⌘ R, I` (Visual Studio (macOS)), `Alt+Shift+I` (Eclipse), `⌘ ⌥ I` (Eclipse (macOS))

The Inline refactoring lets you reverse the Extract refactoring for a method, constructor, parameter, superclass, anonymous class, and closure (for Swift).

You can inline the [pattern variable](extract-variable.html) since the Java 14 version. In this case, all the occurrences will be replaced with old-style cast expression.

Procedure:

1. Place the caret at the code fragment you want to inline.

2. Press `Ctrl+Alt+N` (Windows), `⌘ ⌥ N` (macOS), `⌘ ⌥ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ N` (macOS System Shortcuts), `Ctrl+Alt+N` (XWin), `Ctrl+Alt+N` (GNOME), `Ctrl+Alt+N` (KDE), `Ctrl+Alt+N` (Emacs), `Ctrl+Alt+N` (Sublime Text), `⌘ ⌥ N` (Sublime Text (macOS)), `Ctrl+Alt+N` (NetBeans), `Ctrl+R, I` (Visual Studio), `⌘ R, I` (Visual Studio (macOS)), `Alt+Shift+I` (Eclipse), `⌘ ⌥ I` (Eclipse (macOS)). Alternatively, right-click the code fragment and select the inline refactoring that you need from the `Refactor` menu.

3. In the Inline dialog, specify the options.

4. (Optional) Select Preview to preview changes.

5. Preview and apply changes.

Currently, IntelliJ&nbsp;IDEA provides the Inline Function refactoring, which is opposite to the [Extract method](extract-method.html) refactoring.

## Examples

### Inline Variable

Inline Variable refactoring replaces redundant variable usage with its initializer.

&gt; **Note:**
&gt; The variable must be initialized at declaration. If the initial value is modified somewhere in the code, only the occurrences before modification will be inlined.

Example 1

Before:

```JAVA
public void method() {
    int number = anotherClass.intValue();
    int b = a + number;
}

```

After:

```JAVA
public void method() {
    int b = a + anotherClass.intValue();
}
```

Example 2

Before:

```JAVA
public void method() {
    AnotherClass.InnerClass aClass = anotherClass.innerClass;
    int a = aClass.i;
}
```

After:

```JAVA
public void method() {
    int a = anotherClass.innerClass.i;
}

```

### Inline Method

Inline Method results in placing the method's body into the body of its caller(s).

Example 1

Before:

```JAVA
public void method() {
    int c=add(a,b);
    int d=add(a,c);
}

private int add(int a, int b) {
    return a+b;
}
```

After:

```JAVA
public void method() {
    int c= a + b;
    int d= a + c;
}
```

Example 2

Before:

```JAVA
public ArrayList method() {
    String[] strings = {"a","b","c"};
    ArrayList list=add(strings);
    return list;
}

private ArrayList add(String[] strings) {
    ArrayList list = new ArrayList();
    for (int i=0; i&lt; strings.length; i++)
    {list.add(strings[i]);}
    return list;
}
```

After:

```JAVA
public ArrayList method() {
    String[] strings = {"a","ab","abc"};
    ArrayList list1 = new ArrayList();
    for (int i=0; i&lt; strings.length; i++)
    {list.add(strings[i]);}
    ArrayList list = list1;
    return list;
}
```

### Inline Abstract Method

Inlining an abstract method that has exactly one implementation replaces calls to the method with the concrete implementation's code and removes the need for the method declaration and its call.

Before:

```JAVA
public interface AnInterface {
    int readValue();
}

class AClass implements AnInterface {
    public int readValue() {
        return 1;
    }
}

class UserClass{
    void doSmth(){
        AnInterface a = new AClass();
        int i = a.readValue();
    }
}
```

After:

```JAVA
public interface AnInterface {
    int readValue();
}

class AClass implements AnInterface {
    public int readValue() {
        return 1;
    }
}

class UserClass{
    void doSmth(){
        AnInterface a = new AClass();
        int i =1;
    }
}
```

### Inline Constructor

Inline Constructor allows compressing a chain of constructors if one of them is a special case of another.

Before:

```JAVA
public class Class {
    public int varInt;
    public Class() {
        this(0);
    }

    public Class(int i) {
        varInt=i;
    }

    public void method() {
        Class aClass=new Class();
    }
}
```

After:

```JAVA
public class Class {
    public int varInt;
    public Class(int i) {
        varInt=i;
    }
    public void method() {
        Class aClass=new Class(0);
    }
}
```

### Inline Superclass

The Inline Superclass refactoring results in pushing superclass' methods into the class where they are used and removing the superclass.

Before:

```JAVA
              public class Bar {
...
                  int calculations1() { ... }
                  int calculations2() { ... }
              }

              class Foo extends Bar {
                  int someMethod() {
    ...
                      if (something &gt; calculations1()) {
        ...
                          return calculations2();
                      }
    ...
                  }
              }
```

After:

```JAVA
               public class Bar {
...
                   int calculations1() { ... }
                   int calculations2() { ... }
               }

               class Foo extends Bar {
                   int someMethod() {
    ...
                       if (something &gt; calculations1()) {
        ...
                           return calculations2();
                       }
    ...
                   }
               }
```

### Inline to Anonymous Class

Inline to Anonymous Class refactoring allows replacing a redundant class with its contents. Starting with Java 8, the inlined anonymous classes can be converted to lambdas automatically.

Before:

```JAVA
import java.util.*;

public class Main {
    public class MyComparator implements Comparator<string> {
        @Override
        public int compare(String s1, String s2) {
            return 0;
        }
    }

    void sort(List<string> scores) {
        scores.sort(new MyComparator());
    }
}
```

After:

```JAVA
import java.util.*;

public class Main {

    void sort(List<string> scores) {
        scores.sort((s1, s2) -&gt; 0);
    }
}
```

### Inline Parameter

The Inline Parameter refactoring allows you to replace usages of the parameter with the value from the arguments of the method call.

Before:

```JAVA
public class HelloWorld {
      public static void main(String[] args) {
          int score = getScore(5);
          System.out.println("Score: " + score);
      }

      public static int getScore(int base) {
          return base * 10;
      }
}
```

After:

```JAVA
public class HelloWorld {
      public static void main(String[] args) {
          int score = getScore();
          System.out.println("Score: " + score);
      }

      public static int getScore() {
          return 5 * 10;
      }
}
```

## See also

### Procedures

[Code refactoring](refactoring-source-code.html)

### Procedures

[Inline dialogs](inline-dialogs.html)   [Extract/Introduce variable](extract-variable.html)   [Extracting variables in Style Sheets](style-sheets.html)

</string></string></string></body></html>