[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [DotGNU]How do you simulate an inner class in C#?
From: |
Gopal V |
Subject: |
Re: [DotGNU]How do you simulate an inner class in C#? |
Date: |
Sun, 25 May 2003 19:29:28 +0530 |
User-agent: |
Mutt/1.2.5i |
If memory serves me right, Mohan Embar wrote:
> At first glance, this seems right, although you will have to support some
> other constructs too, like the outer this pointer.
That's a new node in the tree that's all :-)
> >From everything I see, inner classes (actually, we're talking non-static
> member classes, since inner classes also include anonymous and local
> classes) are the same as nested classes except they have the outer
> class' this pointer.
Method Outer. Inner(Outer)
0 aload_0
1 invokespecial #4 <Method java.lang.Object()>
4 aload_0
5 aload_1
6 putfield #5 <Field Outer this$0>
9 return
Method void Foo()
0 aload_0
1 getfield #5 <Field Outer this$0>
4 bipush 10
6 putfield #6 <Field int x>
9 return
Seems to be the code Javac generates ... which means that each inner
class contains a 'this$0' which is implicit in the constructor .
After poking around the JVM output , I found that java classes can
be marked as "static" using 0x0008 bit in its visibility bitset.
The only problem I can see is how to mark this as such ... like
how to differentiate inner classes from nested classes in IL code.
Maybe yet another custom attribute ?
> They can be accessible from outside (public class Inner) - I think they're
> like nested classes with the outer this pointer. ^Tum?
No I just tried it ... they have to called from a context where the
"this" is the direct enclosing class of Inner ..
Gopal
--
The difference between insanity and genius is measured by success
RE: [DotGNU]How do you simulate an inner class in C#?, Thong \(Tum\) Nguyen, 2003/05/25
Re: [DotGNU]How do you simulate an inner class in C#?, Gopal V, 2003/05/27