Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Playing with inner classes

Status
Not open for further replies.

Diancecht

Programmer
Jan 8, 2004
4,042
ES
I was jumping around inner classes. How can you know if an object is an instance of an inner class?

My first thought was looking for the $ character in the class name, as some commercial implementations do.

But I did a concept proof. I declared a class Po$tato and it worked, so no chance.

I the looked at the getDeclaringClass method of class Class, and I think I found the solution there.

So why am I posting this? Mainly to know if anyone had faced this before or if anyone knows about reserved characters on class names.

Cheers,

Dian
 
Why would you care if the class was inner or not Dian ?

--------------------------------------------------
Free Database Connection Pooling Software
 
Well there's no reason, just playing around.

There's common tecnique that uses inner classes to add event handlers. I was thinking on a way to know if an event has been caught by any of those classes. The reason behind is a bit tricky, it has to do with sending application events before the Swing events that caused them.

I managed to get it work by other means, but then I started being curious about what would happen if I include a $ in a class name.

Now I think that the $ is just a convention and compiler does not make any difference between inner and "outer" classes.

Cheers,

Dian
 
ASFAIK the whole $ thing is just something started by the Sun compiler - but I don't believe its in the compiler spec.

--------------------------------------------------
Free Database Connection Pooling Software
 
IBM compiler does the same.

The surprise for me is that some Apache utils classes use that $ to determine wether a class is inner or no (don't ask me why)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top