mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. dev
  3. Main content

java 嵌套类的实例化问题

2011-11-08 110hotness 0likes 0comments

No enclosing instance of type Foo is accessible. Must qualify the allocation with an enclosing instance of type Foo (e.g. x.new A() where x is an instance of Foo).




You can get the error

 No enclosing instance of type Foo is accessible. Must qualify the allocation with an enclosing instance of type Foo (e.g. x.new A() where x is an instance of Foo).

if you try to instantiate an inner class without an instance of the outer class.


@@@ check!


WRONG

 class Foo
{
private class Bar
{
// stuff
}
}
class Baz
{
Foo.Bar aBar = new Foo.Bar(); // wrong!
}

WRONG

 class Foo
{
private class Bar
{
// stuff
}
}
class Baz
{
Foo.Bar aBar = (new Foo).new Bar();
}

Tag: Nothing
Last updated:2011-11-08

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang