Re: Has Java become too complicated?




"Lew" <lew@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:Foadnfs9ld7aVULYnZ2dnUVZ_ruknZ2d@xxxxxxxxxxxxxx
Mike Schilling wrote:
I don't know what you mean by "instances created within the enclosing
object". Static fields of an inner class would, logically, act exactly
like static fields of any other class: accessible as fully-qualified name
to any code that is allowed to access them, and as simple names within
the class itself. (For anonymous and local classes, which have no
fully-qualified names, only visible within the class.) This wouldn't be
difficult to implement; in fact, I suspect all that would be necessary is
removing the current checks that make non-constant static members
illegal.

Not true. Inner classes belong to an instance of the enclosing class.

No, inner class *instances* have an enclosing *instance*.


So, for example, (untested)

public class Foo
{
class Bar
{
}

public static void main( String [] args )
{
Foo a;
Foo b;
}
}

In this example, a.Bar and b.Bar are /different/ classes. They cannot
share static non-constant members.

There's only one class; it's called Foo$Bar. Try running the following
program:

public class Foo
{
class Bar
{
}

public static void main( String [] args )
{
Foo a = new Foo();
Foo b = new Foo();

Bar ab = a.new Bar();
Bar bb = b.new Bar();

System.out.println(ab.getClass());
System.out.println(bb.getClass());
System.out.println(ab.getClass() == bb.getClass());

}
}


.



Relevant Pages

  • Re: NOOB QUESTION: How can I access an element in nested classes
    ... function ChangeA() does not work because 'a' doesn't belong to Bar; ... belongs to Foo. ... class Bar change an element that belongs to Foo? ... public void DoSomethingWithBar() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Q] best way to inject new functionality into a class
    ... module Foo ... class Bar ... Intro to Ruby on Rails January 12-15 Fort Lauderdale, ...
    (comp.lang.ruby)
  • Re: Inherited class
    ... public class bar: foo ... Public Integer i ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Friend a good idea here?
    ... > class Foo ... to put it in a common function and call it in both constructors. ... > The other question is about the use of friend in general here. ...
    (comp.lang.cpp)
  • Re: accessor/mutator - design flaw
    ... > nonetheless I've been advised that multiple uses of accessor/mutator ... > consider the class BAR which has a member data in_use that FOO ... Similarily FOO has member data 'idx' that BAR ...
    (comp.lang.cpp)