inner-classes

Allowing garbage collection of a class while an anonymous inner class instance is referenced elsewhere?

I have a class A: public class A { private B b = new B() { public void method() { do something } }; public B getB() { return b; } } public interface B { void method(); } The instance b has an implicit reference of the instance of its outer class (that can be referenced by this). Now another object gets a reference to this b ...

Is it possible to create an instance of nested class using Java Reflection?

Hello, Sample of code: public class Foo { public class Bar { public void printMesg(String body) { System.out.println(body); } } public static void main(String[] args) { // Creating new instance of 'Bar' using Class.forname - how? } } Is it possible to cr...

visual c++ inner class as a property, possible ?

Hello, As a C++ programmer I've recently started to work with visual c++. I've get stuck with the properties. The idea is to create an inner class that would have 2 methods plus property like get/set functions. Does it even possible in visual C++ (i guess yes). The usage would be like this: Foo ^ foo = gcnew Foo(); int a; foo->Metho...

Referring to the type of an inner class in Scala

The following code tries to mimic Polymorphic Embedding of DSLs: rather than giving the behavior in Inner, it is encoded in the useInner method of its enclosing class. I added the enclosing method so that user has only to keep a reference to Inner instances, but can always get their enclosing instance. By doing this, all Inner instances ...

Instantiating a non-static Java Inner Class from JRuby

So given the following java class: class Outer { private int x; public Outer(int x) { this.x = x; } public class Inner { private int y; public Inner(int y) { this.y = y; } public int sum() { return x + y; } } } I can create an instance of the inner class from Java in the following manner: Outer o = new Outer(1);...

how to reference a higher class within an anonymous class

I have this code: public class Home extends Activity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... //at some point I have s.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){ @Override public ...

In Java nested classes, can the enclosing class access private members of inner classes?

In Java, the inner class can access private members of enclosing class. But can the outer class access private members of inner class? This is irrespective of whether inner class is static or not. I thought this is not true but the following code seems to compile and work fine. public class Outer { class Inner { private int ...

Problem with Inner Class. Illegal Start of Expression error

Hi, I am practicing using inner classes but am having difficulty with a homework question: It is as follows: Create a Swing component class BetterButtons that extends JPanel and has three Jbutton instances labelled "One", "Two", and "Three". In the constructor of BetterButtons, write a local class ButtonListener that implements Action...

(nested?) anonymous inner classes for buttons

I've used an anon inner class to get a button obj: Button modButton = new Button("Modify"); modButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { //TODO: link to a pop-up, and do a refresh on exit } }); I want to use this in an arbitrarily sized GWT FlexTable (which is bas...

Java (anonymous or not) inner classes: is it good to use them ?

In some of my projects and in some books was said to not use inner class (anonymous or not, static or not) - except in some restricted conditions, like EventListeners or Runnables - is a best practice. They even were 'forbiden' in my first industry project. Is this really a best practice? Why? (I have to said I use them a lot...) -- E...

Subinstances sharing a common superinstance

I have a class Super and several subclases Sub1, Sub2,... Is there a way to instantiate objects sub1, sub2 that would share the same super instance? The situation comes from an inner nested class configuration like this: Super{ superFields... Sub1{...} Sub2{...} ........ } But the inner claeses have grown too m...

Spring: Injecting a private inner class as an outer class's member?

Hi I have the following class structure public class Outer{ private Mapper a; .... private class MapperA implements Mapper { } private class MapperB implements Mapper { } } In my Spring config file I would like to create a an Outer bean, and assign one of MapperA or MapperB as a property. Is this possible?...

Java inner classes in c#

I have the following Java code: public class A { private int var_a = 666; public A() { B b = new B(); b.method123(); System.out.println(b.var_b); } public class B { private int var_b = 999; public void method123() { System.out.println(A.this.var_a); ...

inner class within Interface

is that possible to create a inner class within an interface? If yes, why do we create like that? Anyways we are not going to create any interface objects? Do they help in any Development process? ...

How to access "overridden" inner class in Scala?

I have two traits, one extending the other, each with an inner class, one extending the other, with the same names: trait A { class X { def x() = doSomething() } } trait B extends A { class X extends super.X { override def x() = doSomethingElse() } } class C extends B { val x = new X() // here B.X i...

What are the interets of synthetic methods?

Problem One friend suggested an interesting problem. Given the following code: public class OuterClass { private String message = "Hello World"; private class InnerClass { private String getMessage() { return message; } } } From an external class, how may I print the message variable content...

Why can we have static final members but cant have static method in an inner class ?

Why can we have static final members but cant have static method in an inner class ? Can we access static final member variables of inner class outside the outer class without instantiating inner class ? ...

Why my inner class DO see a NON static variable?

Earlier I had a problem when an inner anonymous class did not see a field of the "outer" class. I needed to make a final variable to make it visible to the inner class. Now I have an opposite situation. In the "outer" class "ClientListener" I use an inner class "Thread" and the "Thread" class I have the "run" method and does see the "ear...

Accessing the shadowed field from enclosed member class (Java)

is it possible to access a shadowed field of an enclosing class from the enclosed one in Java? public class Inherit { public int a = 3; private int b = 5; public class Inheriting { public int a = 23; private int d = 8; public void f() { System.out.println("Here I want to get a = 3");...

Rails class << self

Hey. I would like to understand what "class << self" stands for in the next example. module Utility class Options #:nodoc: class << self def parse(args) end end end end Thx! ...