Message Board


Message Board > Programming > The mysteries of Java

August 18, 2012, 02:10
Zomg
None
641 posts
I thought I knew Java quite well until someone came to me with horrible code.

This code.. it was spaghetticode all over. The first mistake he made was declaring and initializing his variables from his inner class inside the inner class, inside the if statement. Then he was wondering why he couldn't access them. Anyway, there were a lot of errors, but the thing that baffled me the most was:

How the heck do you call a public method from an inner class or how do you call an outer method from within an inner class? The secret lies in that the inner class implicitly has a hidden 'this. or new.' reference to its 'encapsulating class'. You must write:
Code:
Outer.this.MyInner.doStuff();

or if you want to access the inner class from inside the outer class:
Code:
Outer o = new Outer();
Outer.Innerclass = o.new InnerClass();

Seriously, that is the most fucked up Java code I have ever seen, but it exists. Its nature arises when people put ALL THEIR CODE INSIDE ONE CLASS. LMAO

Oh well, ya know.
Learned something new.
____________
#

Message Board > Programming > The mysteries of Java

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!