javaintellij-idea

Underlining variables in intelliji


I have some code like blow

public class SimplePizzaFactory {
    public Pizza createPizza(String type) {
        Pizza pizza = null;
        if(type.equals("cheese")) {
            pizza = new CheesePizza();
        } else if(type.equals("greek")) {
            pizza = new GreekPizza();
        } else if(type.equals("pepperoni")){
            pizza = new PepperoniPizza();
        } else {
            throw new IllegalArgumentException();
        }
        return pizza;
    }
}

And I don't understand why underline appear with pizza variable

enter image description here

I have searched on google for a couple hours, but I am not sure what is the meaning of this symbol.

When I change Pizza pizza = null; to Pizza pizza;, underline disappear.

Please help me, thanks in advance!

Edit:

The purpose of question to find the reason why intellij do it like that. Maybe it is too easy, but sometime, there are many easy things we don't know.

First, I think, it is error on my code, there are some questions on my mind, like: why we don't need initilize value of varible, and what is the function of underline?

Second, As i said, I spend hours to find the answer, I have found the posts, maybe its problem like my post, but when I read all the answer, I'm still confusing, because I think, its not problem to intellij do it like, yeah, the firsh though. Maybe, it represent other things, I really know what it is. That's reason. I posted my question.

So, I hope the community understand the confuse on my mind, its simple if we have much experient with java and intellij

Anyway, Thanks to explain for me. The problem is only variable was changed on method like @Jorn answered

Update:

I want to delete this question, how can I delete it?, I read I've thought better of my question; can I delete it? many times, but I'm confused about the steps to delete it.


Solution

  • That's just the way IntelliJ renders mutable variables. Removing the = null initializer changes the variable to effectively final, so that's why the underline disappears.