Back to Intellij Community

NewInstanceOfSingleton

plugins/groovy/groovy-psi/resources/inspectionDescriptions/NewInstanceOfSingleton.html

2025.3-rc-2333 B
Original Source

Reports new instance creation of classes annotated with @groovy.lang.Singleton. Such constructions can lead to runtime exception Can't instantiate singleton.

Example:

@Singleton
  class Foo{
  }

  Foo foo = new Foo()

After the quick-fix is applied:

@Singleton
  class Foo{
  }

  Foo foo = Foo.instance