开发者

Are groovy variables null-initialized, or is this an IntelliJ bug?

开发者 https://www.devze.com 2023-01-21 06:26 出处:网络
IntelliJ highlights the \'foo\' variable in gray, and says \"assignment is not used\". What I want to know is - it is right or not...

IntelliJ highlights the 'foo' variable in gray, and says "assignment is not used". What I want to know is - it is right or not...

If this were java and not groovy, I know it wouldn't be right.

public class Foo
{
  public Foo()
  {
    Foo foo = null; // this 'foo' instance is gray ("assignment not used")
    try
    {
      foo = new Foo()
      // ...
    }
    finally
    {
      if (foo != null)
        foo.release();
    }

  }

  public void relea开发者_C百科se(){}
}


Groovy (and Java) local variables must be explicitly initialized before use. Java Language Specification: Initial Values of Variables.

A local variable (§14.4, §14.14) must be explicitly given a value before it is used, by either initialization (§14.4) or assignment (§15.26), in a way that can be verified using the rules for definite assignment (§16 (Definite Assignment)).


It is a bug. I've created an issue http://youtrack.jetbrains.net/issue/IDEA-81188

0

精彩评论

暂无评论...
验证码 换一张
取 消