Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull variable up Intellij IDEA?

Is there any way to pull variable up outside try-catch block with shortcut? For example:

from:

try{
    AbstractList<Type> t1 = new ArrayList<Type>();
} catch (Exception e) {
    ...
}

to

AbstractList<Type> t1;
try{
    t1 = new ArrayList<Type>();
} catch (Exception e) {
    ...
}
like image 735
mariolos Avatar asked Feb 17 '15 21:02

mariolos


1 Answers

I know how to do this with a few shortcuts:

  1. put your cursor on t1 and then "Show intention actions". From there, select "Split into declaration and assignment". Your code will now look like this:

    try {
        AbstractList<String> t1;
        t1 = new ArrayList<String>();
    } catch (Exception e) {
        e.printStackTrace();
    }
    
  2. Put your cursor on the line with the declaration.
  3. Do the "move statement up" action. Now your code will look like this:

    AbstractList<String> t1;
    try {
        t1 = new ArrayList<String>();
    } catch (Exception e) {
        e.printStackTrace();
    }
    
like image 186
Daniel Kaplan Avatar answered Sep 29 '22 16:09

Daniel Kaplan