inner-classes

Anonymous inner class in groovy

I am looking into the groovy-wicket integration and lack of anonymous inner classes seems to be a problem when writing the event handlers. Is there a groovier way of writing this code import org.apache.wicket.PageParameters import org.apache.wicket.markup.html.basic.Label import org.apache.wicket.markup.html.link.Link import org.apache....

Java: Name ambiguity between outer and inner class methods.

Suppose I have: public class OuterClass() { public class InnerClass { public void someMethod(int x) { someMethod(x); } } public void someMethod(int x) { System.out.println(x); } } How do I resolve the ambiguity between the someMethod() of the outer class and the someMethod() of the inner...

Friend methods/classes for AS3 packageless classes

Hi I'm wondering if I can have a packageless () AS3 class call a private method on the main class in the file. For example: package demo { public class MyDemoClass { var helper:FriendlyHelperClass = new FriendlyHelperClass(this) } private function methodToCall():void { ... } } public class Frien...

Can't access protected inner class while inheriting.

Reading through "Thinking in Java" i stuck in ex:6 of Inner Classes chapter. Exercise 6: (2) Create an interface with at least one method, in its own package. Create a class in a separate package. Add a protected inner class that implements the interface. In a third package, inherit from your class and, inside a method, return an obj...

Declare but not define inner struct/class - legal C++ or not?

Is following code legal C++ or not? class Foo { class Bar; void HaveADrink(Bar &bar); void PayForDrinks(Bar &bar); public: void VisitABar(int drinks); }; class Foo::Bar { public: int countDrinks; }; void Foo::HaveADrink(Bar &bar) { bar.countDrinks++; } void Foo::PayForDrinks(Bar &bar) { bar.countDrinks = 0; } void ...

Subclassing Inner Class from Outer Class versus other Inner Class

I am befuddled why this is allowed public class Foo { class Bar extends Foo { } } Yet this is not allowed public class Foo { class Bar extends Foo { } class Fooey extends Bar { } } The compiler informed that it can not reference Fooey.this before supertype constructor has been called. And this is allowed ...

Null Object When Passed Into An Anonymous Inner Class

When passing a final object (A String in the code below) it shows up as null when printed from the anonymous inner class. However, when a final value type or straight final String is passed in, its value is correctly displayed. What does final really mean in context of the anonymous inner class and why is the object passed null? publi...

Java reflection: How can I retrieve anonymous inner classes?

Hello, everyone! I have an anonymous inner class inside another class (SomeClass). Both SomeClass.class.getClasses() and SomeClass.class.getDeclaredClasses() return empty arrays. I couldn't find some hints on this in Class' Javadocs. Can anonymous inner classes be retrieved using reflection in some way? What else are notable differe...

Python data structure/object to model static multidimensional table

I'm just getting back into coding after a few year hiatus and I'm trying to model multi-tiered static forms in a way that lets me grab and perform operations on a specific form level or an entire sub-tree. Example Form hierarchy: MyForm Question 1 Part 1 Question 1.1 Part 2 Question 2.1 SubPart 1 Question 2.1.1 Question 2.1.2 Q...

How many times can classes be nested within a class?

I came across this questions on one of the online Java Tests. The options were 4,5,8 and any number of times. I have only used one inner class, but have never tried multiple ones. I was wondering if anyone knows the answer. ...

Is it ever reasonable to nest Java inner classes more than one level deep?

Kushal Paudyal asked how deep you can nest inner classes in Java. The consensus is that while the language itself imposes no limit, the underlying OS and file system may. Have you ever found a case where two or more levels of nested inner classes are helpful? Update (11/28): If you consider enum classes, a second level of nesting can...

Closures in Java - syntax differences between the three major proposals?

Three major proposals for adding closures to the Java language has been presented: BGGA (Bracha Gafter Gosling Ahé) also known as "full closures", by Gilad Bracha, Neal Gafter, James Gosling and Peter von der Ahé CICE (Concise Instance Creation Expressions) also known as "simplified inner classes", by Bob Lee, Doug Lea and Josh Bloch F...

Getting hold of the outer class object from the inner class object

I have the following code. I want to get hold of the outer class object using which I created the inner class object inner. How can I do it? public class OuterClass { public class InnerClass { private String name = "Peakit"; } public static void main(String[] args) { OuterClass outer = new OuterClass(); Inne...

Standards for using inner classes for GUI?

Hi, I'm wondering about the standard practice with inner classes (in Java but I suppose it applies to all OO languages). So I have a JFrame subclass ControllerWindow that contains a JPanel subclass MapPanel which I draw onto (so it needs to overwrite paintComponent method) and which needs to implement a mouse listener. My current solutio...

Java, inner classes and instanceof

Hello, I coded in NetBeans something like this: public class Grafo<V, E> { class Par { int a, b; Par(int a, int b) { this.a = a; this.b = b; } @Override public boolean equals(Object ob) { if(ob instanceof Par) { Par p = (Par)ob;...

Do java's Inner classes pose a security risk?

Recently the security team on my project released a secure code guidelines document, designed to be used as part of our code reviews. The first thing that struck me was an item that said "Do not use Inner classes". I thought this seemed like a very heavy handed and sweeping statement. Inner classes are good if used correctly right?, but ...

Why does Java prohibit static fields in inner classes?

class OuterClass { class InnerClass { static int i = 100; // compile error static void f() { } // compile error } } Although it's not possible to access the static field with OuterClass.InnerClass.i, if I want to record something that should be static, e.g. the number of InnerClass objects created, it would be helpful to make th...

JYAML: Serialize/deserialize nested/inner classes

First of all, Merry Christmas to everyone! Now to my question: Let's say I have the class Outer with some inner class Inner. As a field in Outer, I have a List<Inner>, which i then want to dump to a YAML file. I do this like so: Outer o = new Outer(); o.innerList = new ArrayList<Inner>(); o.innerList.add(new o.Inner()); ... Yaml.dump(o...

How do I use paramertized generic types in an inner class?

Hello, I am trying to implement an inner class that has generic parameterized type. Here is my code (short version): public class AVLTree<T extends Comparable<? super T>> implements Iterable<T> { ... private class BinaryNode<T extends Comparable<? super T>> { ... } private class TreePreOrderIterator<E extends Comparable<? super...

creating inner classes with spring

What is the best aproach to create a non-static inner class in Spring? class A { public class B {} B b; public void setB(B b) {this.b = b;} } this seems to work, but i want to avoid the need for a constructor argument: <bean id="a" class="A"> <property name="b"> <bean id="b" class="A$B"> <constructor-arg ref="a"/> ...