Enclosing Instances When Subclassing Inner Classes

Hi,
I need to subclass an inner class but when I write code for its constructor I get the error "an enclosing instance that contains at.MainHandler.innerClass is required".
at.MainHandler is my outer class and my new class looks something like this:
public class newClass extends at.MainHandler.innerClass {
     //Constructor
     public newClass (int a, int b) {
         super( a );
    }//Constructor
}//ClassI understand that the inner class to which 'super' refers must somehow be bound to its outer class(at.MainHandler) if I want newClass to access the outer class methods, but what is the correct syntax needed to achieve this?
I've looked at other posts on similar topics but am still unable to grasp precisely what is needed.
Sid

These are some working examples:
class A {
     class InA {}
class B extends A {
     class InB extends InA {}
class A {
     static class InA {}
class InB extends A.InA {}
class A {
     class InA {}
class InB extends A.InA {
     InB(A a) {
          a.super();
}

Similar Messages

  • Can enclosing instance for an inner class be null?

    I have a class Solution, which defines an inner class, SolutionStep.
    In a third class I construct several SolutionStep objects, and later use them to construct a Solution.
    In this third class I have statements like this:
    Solution solution = null;
    aCollection.add(solution.new SolutionStep(arg1, arg2);
    This has been working fine, but recently a customer reported an error,which seems to be a NullPointerException at the line above.
    Now that I look at this code, I'm not very happy about it and I'll clean it up, but I am left with the basic question of whether what I'm doing is legal. Can the enclosing instance used to construct an inner class be null? I have not been able to find a definitive answer.
    Any help appreciated.

    Yes, you're right, I dropped a parenthesis. Sorry.
    The offending statement is actually
    aCollection.add(solution.new SolutionStep(arg1,
    arg2));
    And that is certainly legal. The inner class does not
    need to be qualified when it's constructed in the
    context of an enclosing instance.Very interesting.
    The following code demonstrates this....
        class Solution
            class SolutionStep
                public SolutionStep()
        public class ThirdClass
            static public void main(String[] args)
            Solution solution = null;
            //Solution solution = new Solution();  // This produces no null exception.
            Solution.SolutionStep s = solution.new SolutionStep();
    Using jikes and javac doesn't change the behavior so that means it is VM rather than compiler specific.
    I am using 1.4.2_04 on windows and I get the null pointer exception.
    Looking at the javap output suggests that invokespecial has to be checking this (although I could have overlooked something when I checked.)
    This probably comes from the following in the VM spec under invokespecial...
    Otherwise, if objectref is null, the invokespecial instruction throws a NullPointerException.

  • Subclassing inner class

    I have a class with some private fields that I want to access from several other classes, all of which will inherit from one class.
    I could provide public accessor methods but I don't feel it is appropriate in this situation so I thought of creating an inner class with protected accessor methods to the private fields.
    I would like to subclass this inner class from outside the enclosing class, thus giving access to the private fields without altering the public interface of the enclosing class.
    I have written a small sample program to test this idea.
    public class A{
      private String hello = "Hello";
      public A(){}
      public class B{
        public B(){}
        protected String getString(){
          return hello;
    public class C extends A.B{
      public static void main(String[] args){
        A a = new A();
        A.B c = new C();
      public C(){
        System.out.println(getString());
    }However, compiling this gives the error "No enclosing instance of A is in scope" at the constrctor for C.
    Am I trying to do something impossible or stupid, or is there a simple solution?
    Thanks,
    Tristan.

    You need a reference to an instance of class A inside B or C. When you declare an inner class as you did, you can access this reference by A.this, but in this case B cannot be instantiated outside an instance of A.
    You want to refer a class A.B without an instance to A. You can do that by declaring B as static. But in this case you don't have access to non-static members of A. So, you still need a reference to A.
    Here is a possible solution :
    class A {
        private String hello = "Hello";
        public A() {}
        static public class B {
         protected A a;
         public B(A a){ this.a = a;}
         protected String getString() {
             return a.hello;
    public class C extends A.B {
        public static void main(String[] args){  
         A a = new A(); 
         A.B c = new C(a);
        public C(A a) {
         super(a);
         System.out.println(getString());
    }It is working.
    Anyway the entire story seems too complicated for me :-) Redesigning is not allways a bad idea ...
    Regards,
    Iulian

  • When  we going to use static inner class

    Hi
    when we r going use static inner class
    inner classes use for to create adaptorclasses that implement an interface.
    what about Static inner class
    if possible give some examples
    Thanks in adv

    static inner classes are used when the inner class does not require to access the encompassing class's variables/methods. By default non-static inner classes obtain a reference to the outer class instance through which they access the outer class variables and methods
    ram.

  • Your Opinions: Inner Classes Need static Members

    Hi All,
    I want to solicit opinions for a minor change to the way inner classes work. I submitted this as an RFE to Sun and they rejected it, really without giving a reason. I'd like to know your opinions. If there is strong support I will repost the RFE.
    As you probably know, inner classes cannot have static members. The following generates a compiler error:import java.util.*;
    public class MyClass {
       class MyInnerClass {
          // Next line causes compiler error...
          static Map m = new HashMap();
    }In order to get around this you have to make the Map variable a static member of the containing class:import java.util.*;
    public class MyClass {
       static Map m = new HashMap(); // so much for encapsulation...
       class MyInnerClass {
    }I am suggesting that inner class be allowed to contain static members. Here's my reasoning...please comment:
    There are times when members (i.e., fields and methods) rightfully belong to the class as a whole, not to any particular instance of a class. I'm sure we've all found times when it was necessary to have static members in our classes. The same issues that necessitated using static members in top-level classes make them desirable for inner classes as well.
    Designing a class as an inner class is a step toward encapsulation. By forcing static members that logically belong in an inner class to be declared in the containing class is to crack the encapsulation, IMHO.
    Even though a containing class has access to all of an inner class' members (including private members) and vice versa, I think the notion of inner static members still is more OO-ish.
    What are your opinions? Would allowing inner classes to contain static members make Java more object oriented? I think it would.
    Technically, I don't think there's any reason this cannot work since the JVM has no notion of inner classes, per se.
    What do you think?

    an inner class is effectively a non static instance
    variable of its enclosing class. Instance member, but not a variable. it's a class, a type, not a variable.
    >
    I think the problem here is that making a field static
    means more than just that that field and its value are
    common to every instance of the class. It means that
    the value is valid without an instantiation of that
    class.
    Since the class itself must be instantiated (it is
    not static), What do you mean, excatly, by "_must_ be instantiated"? You are not ever "required" to instantiate anything unless you want to use it.
    you can't have static member data inside it. I don't see how this follows from the previous part of the statement.
    How would you reference the static member data of
    the inner class? You would have to specify an
    instance of the inner class, and since this breaks
    the meaning of static, you can't have static members
    in an inner class.How about outerObj.InnerClass.staticMember The syntax is well defined. The question at hand is, do we really want to allow this? The syntax to do this should only be an issue after that question has been answered in the affirmative. The people at Sun have decided not to allow it, so for now, syntax is a non-issue.
    >
    if you wanted a static member in an inner class you
    could put it in a super class of the inner class...Or in the enclosing class, as suggested in the orginal post.

  • Enclosing instance references....

    Ok, I turned to the holy scripture (JLS), and have turned away baffled.....
    Im confused on an Inner class issue.
    If inner classes are to reference fields of their inclosing instance, they have to be able to reference it some way.
    Im assuming that this is implemented as a field of the inner class (is that a correct assumption?) synthesised at compile time.
    Now, what I want to know is when does this reference (if it exists) become 'valid' when the inner class is a derived class?
    Intuition tells me that it would be null until after the base class constructor had completed. However, in practise this is not always the case....
    Heres an example:
    We have some class:
    class Something {
      public Something() {
        // NOTE: Call non-final method from constructor!!!
        createSomething();
      public Object createSomething() {
        return new Whatever();
    }We then have a class which creates an annonymous inner class which overides the 'createSomething' method:
    class UserClass {
      public void example() {
        final Object toReturn = new Object();
        Something mySomething = new Something() {
          public Object createSomething() {
            // THE ALL IMPORTANT LINE:
            System.out.println("Ref: " + UserClass.this);
            return toReturn;
    }Now, when the mySomething is constructed, the 'createSomething' method is called from the base constructor. At this point, I would expect (incorrectly?) that the enclosing reference (UserClass.this) would be null.
    However, on two compilers, I get two different results. Null on one, non-null on the other.
    Can anyone please explain to me the way this should work - or is it undefined?

    What Im confused about is this:
    The instance of the annonymous inner class has to be able to reference its enclosing instance somehow (I.e, UserClass.this).
    So, Im guessing (perhaps incorrectly...) that the instance of the annonymous inner class will have a field that is a reference to the enclosing class.
    Im fully aware that the enclosing class can never really be null... However, constructors are called bottom up, and a non-final method is called from the base class constructor.
    This is then overidden in the inner class to print out the reference to the enclosing class (UserClass.this).
    My confusion is about when it becomes 'valid' for the inner class to reference its enclosing class (using UserClass.this) - and my intuition says not before the base constructors have been called (I.e, I would expect it to be null in my example).
    Why do I think that?
    Well, if we have this:
    class MyBaseClass {
      public MyBaseClass() {
        dodgyMethod();   
      public void dodgyMethod() {
        System.out.println("HELLO");
    class MyDerivedClass extends MyBaseClass {
      Integer someInteger = new Integer(4);
      public void dodgyMethod() {
        // Will be NULL when called from base constructor
        System.out.println("val: " + someInteger);
    }We see that if a new 'MyDerivedClass' is created, then someInteger is null (because someInteger hasn't been initialised yet, coz we are still in the base class constructor).
    My question is just an extension of the above.....
    If the enclosing instance reference is implemented as a normal ref in the anonymous inner class, I would not expect it to get initialised until the base class constructor had completed (in the same way that I wouldn't expect someInteger to be initialise until its base constructor had completed).
    So its all about calling non-final methods from a base class, where the derrived class is an inner class, and whether or not the enclosing reference should be non-null at that point in time.

  • A question about non-static inner class...

    hello everybody. i have a question about the non-static inner class. following is a block of codes:
    i can declare and have a handle of a non-static inner class, like this : Inner0.HaveValue hv = inn.getHandle( 100 );
    but why cannot i create an object of that non-static inner class by calling its constructor? like this : Inner0.HaveValue hv = Inner0.HaveValue( 100 );
    is it true that "you can never CREATE an object of a non-static inner class( an object of Inner0.HaveValue ) without an object of the outer class( an object of Inner0 )"??
    does the object "hv" in this program belong to the object of its outer class( that is : "inn" )? if "inn" is destroyed by the gc, can "hv" continue to exist?
    thanks a lot. I am a foreigner and my english is not very pure. I hope that i have expressed my idea clearly.
    // -------------- the codes -------------------
    import java.util.*;
    public class Inner0 {
    // definition of an inner class HaveValue...
    private class HaveValue {
    private int itsVal;
    public int getValue() {
    return itsVal;
    public HaveValue( int i ) {
    itsVal = i;
    // create an object of the inner class by calling this function ...
    public HaveValue getHandle( int i ) {
    return new HaveValue( i );
    public static void main( String[] args ) {
    Inner0 inn = new Inner0();
    Inner0.HaveValue hv = inn.getHandle( 100 );
    System.out.println( "i can create an inner class object." );
    System.out.println( "i can also get its value : " + hv.getValue() );
    return;
    // -------------- end of the codes --------------

    when you want to create an object of a non-static inner class, you have to have a reference of the enclosing class.
    You can create an instance of the inner class as:
    outer.inner oi = new outer().new inner();

  • How to call inner class method in one java file from another java file?

    hello guyz, i m tryin to access an inner class method defined in one class from another class... i m posting the code too wit error. plz help me out.
    // test1.java
    public class test1
         public test1()
              test t = new test();
         public class test
              test()
              public int geti()
                   int i=10;
                   return i;
    // test2.java
    class test2
         public static void main(String[] args)
              test1 t1 = new test1();
              System.out.println(t1.t.i);
    i m getting error as
    test2.java:7: cannot resolve symbol
    symbol : variable t
    location: class test1
              System.out.println(t1.t.geti());
    ^

    There are various ways to define and use nested classes. Here is a common pattern. The inner class is private but implements an interface visible to the client. The enclosing class provides a factory method to create instances of the inner class.
    interface I {
        void method();
    class Outer {
        private String name;
        public Outer(String name) {
            this.name = name;
        public I createInner() {
            return new Inner();
        private class Inner implements I {
            public void method() {
                System.out.format("Enclosing object's name is %s%n", name);
    public class Demo {
        public static void main(String[] args) {
            Outer outer = new Outer("Otto");
            I junior = outer.createInner();
            junior.method();
    }

  • Inner Classes doubts

    Hi All,
    I am trying to learn Inner classes in Java. I am referring to the book Core Java by Horstmann and Cornell.
    I know that there are various types of inner classes namely:
    - Nested Inner classes
    - Local Inner classes
    - Annonymous Inner classes
    - static inner classes
    First I am on with Nested Inner classes :
    Following is the code which I am executing :
    package com.example.innerclass;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Date;
    import javax.swing.JOptionPane;
    import javax.swing.Timer;
    public class InnerClassTest {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              TalkingClock clock = new TalkingClock(1000,true);
              clock.start();
    //          JOptionPane.showMessageDialog(null,"Quit Program");
    //          System.exit(0);
    class TalkingClock
         private int interval;
         private boolean beep;
         public TalkingClock(int interval, boolean beep){
              this.interval = interval;
              this.beep = beep;          
         public void start(){
              ActionListener listener = new TimePrinter();
              Timer t = new Timer(interval,listener);
              t.start();
         private class TimePrinter implements ActionListener{
              public void actionPerformed(ActionEvent event){
                   Date now = new Date();
                   System.out.println("At the tone time is : "+now);
                   if(beep)
                        Toolkit.getDefaultToolkit().beep();
    }Following are my doubts :
    1. Why do we need to give the line
    JOptionPane.showMessageDialog(null,"Quit Program");
    System.exit(0);without this line the program doesn't show any output.
    2. I didn't understand this syntax.
    You can write inner object constructor more explicitly using the syntax. :
    outerObject.new InnerClass(construction parameters)
    For e.g.
    ActionListener listener = this.new TimePrinter();
    Here the outer class reference of the newly constructed TimePrinter object is set to this reference of the method that creates the inner class object. the this. qualifier is redundant. However, it is also possible to set the outer class reference to another object by explicilty naming it. For e.g if TimePrinter were a public inner class, you could construct a TimePrinter for any talking clock.
    TalkingClock jabberer = new TalkingClock(1000,true);
    TalkingClock.TimePrinter listener = jabberer.new TimePrinter();
    Please do help me understand this concept.
    Thanks
    Siddharth

    I have understood that this explanation :
    i) assuming that TimePrinter is an inner class of TalkingClock, that you'd need an instance of the later in order to create an instance of the former.Yes.
    Being a non-static inner class, it can not be instantiated out of context ... which context is the outer class.No. See my reply 11. The "context" is an instance of the outer class - it bears repeating.
    ii) jabberer is the outer instance that you are providing.Yes (more accurately it's a reference to an instance of the outer class, but that would be nit-picking).
    The left side is identifying the class, the right side is identifying the instanceNo.
    I'm not sure what you're calling left side and right side.
    If you're talking about both sides of the equals sign, then no, it's completely wrong.
    If you're talking about both sides of the "point" sign, then it's wrong too, just a bit less wrong.
    Let's revise this step by step (good thought process).
    1. in first line we are getting an outer class reference with this code
    TalkingClock jabberer = new TalkingClock(1000,true);
    this line is very natural and easily understood. Yes. The correct wording would be merely "we are getting a reference to an instance of the outer class". Sorry to insist densely.
    2. Now when we come to the second line, i.e. where we try to instantiate an inner class with this line of code
    TalkingClock.TimePrinter listener = jabberer.new TimePrinter();
    - I do understand the concept that we need an instance of outer class in order to create an instance of inner class as inner class is visible only to outer class.No. We need an instance of the outer class as the inner class is non-static, and by definition needs an instance of the outer class. That has nothing to do with visibility (public vs private vs...). Again, some words have special meanings in the Java world.
    - I also do understand that it cant be instantiated out of context. I see you like this expression, but it is too vague and misleads you. Please forget about it for a moment (no offense to otherwise helpful and knowledgeable abillconsl).
    - I also do understand that left side is identifying the class and right side is identifying the instance. ANDAgain I'm afraid of which "sides" you're talking about.
    - that in this line TalkingClock.TimePrinter listener = new TalkingClock().new TimePrinter();
    the outer class is anonymous (new TalkingClock()) as we don't require its name here Poor choice of words again. Anonymous classes do exist in Java, but are a totally different concept, that is not related to this line.
    - Also in this line TalkingClock.TimePrinter listener = jabberer.new TimePrinter();
    I understood the left side part i.e. TalkingClock.TimePrinter listener =
    We are attaching the outer class reference with the inner class that's absolutely understandable. Not at all!
    This just declares a variable listener, whose type is TalkingClock.TimePrinter (or more accurately com.example.innerclass.TalkingClock.TimePrinter).
    Then follows an assignment:
    WHAT I don't understand is the right hand side, i.e., the statement jabberer.new TimePrinter();
    1. I am unable to digest the fact that we can do something like anobject.new
    new is an operator that is used to instantiate an instance of an object. I am unable to digest that we can do x.new?See my previous reply. This is short-hand syntax Sun chose to pass a reference to an instance of the outer class (here, jabberer) to the constructor of the inner class. They could have chosen something else. Again, bear with it.
    I only know that we can do is new SomeClass(); AND NOT instance.new SomeClass();
    Now you know better:
    The second form is valid - only if SomeClass is a non-static inner class defined in a class of which instance is an instance.
    2. Is there something to this conceptually OR this is only a syntax and that I should learn it.
    I want to understand and grasp if there is some concept behind it rather than just learn and mug up. See my previous reply. Each instance of a non-static inner class stores a reference to an instance of the outer class. There must be a way (a syntax) to specify which instance (of the outer class) should be stored in the instance (of the inner class).
    This particular syntax is just a syntax, the "concept" is that the instance of the inner class stores a (unmodifiable) reference to the instance of the outer class that was specified when the instance of the inner class was created.
    I don't know if that deserves to be called a concept, but that's an interesting thing to keep in mind (there are some not-so-obvious implications in terms of, e.g. garbage collection).
    Best regards.
    J.

  • Why and how to use "inner class"

    When i am learning advanced java language features,
    i could not understand why and when to use the "inner class",
    who can give me some examples?
    Thanks!

    You would use an inner class when an object needs visibility of the outer class. This is akin to a C++ friend.
    An example of this is an iterator. An iterator over some collection is typically implemented as an inner class of the collection class. The API user asks for an Iterator (from the Collection) and gets one - in fact they receive an instance of an inner class, but doesn't care. The iterator needs to be inner, as the iterator needs to see the internal data structures of the outer (collection) class.
    This could also be done with an anonymous class, as mentioned by spenhoet above. However, in the case of a collection, the role of the iterator is clear - thus it deserves its own class. And often there is more than one place an iterator can be returned (e.g. see java.util.List, which has several methods that return Iterators/ListIterators), thus it must be put in its own class to allow reuse of the code by outer class.

  • Why we are making a variable as final in method inner class ?

    Why we are making the variable as final (method inner class) while we are accessing the method variable in inner class ?
    regards,
    namanc

    As far as I can tell, the only reason is to protect the programmer: when the inner class instance is constructed, it is given the then-current value of the variable. If the variable (or method parameter) later changes, the value held by the inner class would not. By making the variable final, the programmer doesn't have to worry about them staying in sync.
    Here's some code to ponder:
    public class InnerExample
        void printMe( final int x )
            Runnable runMe = new Runnable()
                public void run()
                    System.out.println(x);
            (new Thread(runMe)).start();
    }When compiled with the Sun JDK 1.4.2, you get this bytecode:
    void printMe(int);
      Code:
       0:   new     #2; //class InnerExample$1
       3:   dup
       4:   aload_0
       5:   iload_1
       6:   invokespecial   #3; //Method InnerExample$1."<init>":(LInnerExample;I)V
       9:   astore_2
       10:  new     #4; //class Thread
       13:  dup
       14:  aload_2
       15:  invokespecial   #5; //Method java/lang/Thread."<init>":(Ljava/lang/Runnable;)V
       18:  invokevirtual   #6; //Method java/lang/Thread.start:()V
       21:  returnAt line (byte) 5, it loads the passed value onto the stack; at line 6, it invokes the inner class constructor (which is created by the compiler). Nothing in this sequence of code would prevent use of a non-final variable.

  • Reason for not allowing static declarations inside an inner class

    Is the reason for not allowing static declarations inside an inner class is due to the fact that it can never be accessed at a class level as the outer class has to create an instance of the inner class and any attributes/methods of the inner class has to be accessed through that.
    Typically, an instance (non-static) variable can never be accessed in a statement or expression inside a static context but the class variable can be accessed inside a non-static context. Given this, shouldnt the static declarations be allowed inside an inner class?
    Correct me if my understanding is wrong.
    Thanks

    I still couldnt get it clearly. Why i cant i have a static value ( variable ) for all the instances of the inner class irrespective of its enclosing instances of it ( i.e outer class instances). Say in this example below,
    class Outer
    static int i = 0;
    public Inner inner = new Inner();
    class Inner // inner class ( non-static nested class )
    int j = 0;
    static final int k = 2; // compile time constants are allowed
    // ininner class
    public void m1()
    j++;
    System.out.println("j is " + j);
    i++
    System.out.println("i is " + i);
    public static void main(String[] arg)
    Outer outer1 = new Outer();
    outer1.inner.m1(); // j will be 1 & i will be 1
    Outer outer2 = new Outer();
    outer2.inner.m1() // j will be 1 again & i will be 2. But I would
    // want j to be 2. Why is this not allowed?
    Looks like something missing..

  • Enclosing instance

    I've never seen this error before. I was trying to create a instance of an inner-class. The code is declared like this:
    static ShuttleController shuttleControl;Then it is created in the main Method like this:
    shuttleControl = new ShuttleController();I'm using eclipse to program this code and it gave me this error:
    No enclosing instance of type SpacePanel is accessible. Must qualify the allocation with an enclosing instance of type SpacePanel (e.g. x.new A() where x is an instance of SpacePanel).This is the code for the class ShuttleControlle:
    class ShuttleController implements Runnable
              public ShuttleController()
              public void run()
                   shuttle.update(WIDTH/2, HEIGHT/2, rotation);
                   xPos += xMom;
                   yPos += yMom;
         }This class is an inner-class in the class SpacePanel

    Objects of an "inner class" can access the instance of the enclosing class and its fields; therefore, they must have an implicit reference to the enclosing object, and cannot be instantiated in static context.
    Maybe you are looking for a "nested class" instead, which does not have a reference to the enclosing object. To do that, you add the "static" keyword:
    static class ShuttleController implements RunnableEdited by: spoon_ on Dec 15, 2007 10:21 PM

  • Threaded inner classes & heap memory exhaustion

    (_) how can i maximize my threading without running out of
    heap memory?
    push it to the limit, but throttle back before an
    java.lang.OutOfMemoryError.
    (_) within 1 threaded class ThreadClass, i have two threaded inner classes. for each instance of ThreadClass i only
    start one instance of each inner class.
    and, i start hundreds of ThreadClass, but not until the previously running ThreadClass object exits, so only one should be running at any given time.
    so, what about threaded inner classes?
    are they good? bad? cause "OutOfMemoryErrors"?
    are those inner threads not dying?
    what are common causes of:
    java.lang.OutOfMemoryError: java heap space?
    my program runs for about 5-minutes, then
    bails with the memory error.
    how can i drill down and see what
    is eating-up all my memory?
    thanks.

    A Thread class is not the same as a thread of
    execution. Those inner class based threads of
    execution are not dying.maybe. but this is the way i test a thread's life:
    public void run() {
    System.out.println("thread start");
    System.out.println("thread dies and release memory");
    }for each inner thread, and the outer thread, this approach for
    testing thread life reveals that they die.
    Why don't you use a thread pool?ok. i will think about how to do this.
    >
    If not, you need to ensure those inner threads have
    exited and completed.what is a 100% sure check to guarantee a thread exits other than
    the one i use above?
    note:
    the outer thread is running on a remote host, and the inner threads
    are running locally. here are the details:
    public class BB implements Runnable, FinInterface {
      public void run() {
        // do some work on the remote machine
      private void startResultsHandler(OisXoos oisX) {
         ResultHandler rh = new ResultHandler(oisX);
         rh.start();
      public void startDataProxy(OisXoos oisX, String query) {
         DataProxy dp = new DataProxy(oisX, query);
         dp.start();
            public class ResultsHandler extends Thread {
               // runs locally; waits for results from servers
               public void run() {
                   ObjectInputStream ois = new ObjectInputStream(oisX.input);
                    Set result = (Set) ois.readObject();
            }  // ____ class :: _ ResultsHandler _ :: class ____
           public class DataProxy extends Thread {
               // runs locally; performs db queries on behalf of servers
               public void run() {
                   ObjectOutputStream oos = new ObjectOutputStream(oisX.output);
                    while(moreData) {
                        .... // sql queries
                        oos.writeObject(data);
                 StartResultsHandler(oisX);
            } // _____ class  :: _ DataProxy _ :: class _____
    }now, the BB class is not started locally.
    the inner threads are started locally to both service data requests
    by the BB thread as well as wait for its results.
    (_) so, maybe the inner threads cannot exit (but they sure look
    like they exit) until their parent BB thread exits.
    (_) yet, those inner threads have no knowledge that the BB
    thread is running.
    externalizing those inner thread classes will put 2-weeks of work
    in the dust bin. i want to keep them internal.
    thanks.
    here this piece of code that controls everything:
    while(moreData) {
      FinObjects finObj = new BB();
      String symb = (String) data_ois.readObject();
      OisXoos oisX = RSAdmin.getServer();
      oisX.xoos.writeObject(finObj);
      finObj.startDataProxy(finObj, oisX, symb);
    }

  • Passing Inner class name as parameter

    Hi,
    How i can pass inner class name as parameter which is used to create object of inner class in the receiving method (class.formane(className))
    Hope somebody can help me.
    Thanks in advance.
    Prem

    No, because an inner class can never have a constructor that doesn't take any arguments.
    Without going through reflection, you always need an instance of the outer class to instantiate the inner class. Internally this instance is passed as a parameter to the inner class's constructor. So to create an instance of an inner class through reflection you need to get the appropriate constructor and call its newInstance method. Here's a complete example:import java.lang.reflect.Constructor;
    class Outer {
        class Inner {
        public static void main(String[] args) throws Exception{
            Class c = Class.forName("Outer$Inner");
            Constructor cnstrctr = c.getDeclaredConstructor(new Class[] {Outer.class});
            Outer o = new Outer();
            Inner i = (Inner) cnstrctr.newInstance(new Object[]{o});
            System.out.println(i);
    }

Maybe you are looking for

  • Nokia c5-03 SW update

    Thank you for your SW update, current  problems are resolved 1.when i check s.w update it apears "Phone software" instal through pc 2.when prees menu button 2beep sound. but recorded videos have struck its continue and mark to delete or move content

  • Mail Account sync from mac to iPhone

    i cant sync my mail accounts from my mac to my iphone 4! the register "info" isnt there in iTunes. so i have to type all the settings on the iphone again. with mountain lion it was really easy to sync my mail accounts. why is this function not includ

  • My keyboard won't connect to imac

    I have a 2011 imac that has worked fine for several months but I recently installed some bad ram that caused my computer to do some crazy things.  It stopped recognizing the wireless keyboard that came with it and has been used with it for 6 months. 

  • Blank pics in iphoto, what do i do??!

    hi- all my pictures in my iphoto library after 2005 are blank gray squares, but still in the library. when i try and access these pics in another part of my computer, they are still blank. has anyone had this problem? what can i do? Emac   Mac OS X (

  • Deprecated warnings while using XMLBeans

    Greetings, Using XMLBeans Builder in WorkShop 9.2 raises hundreds of deprecated warnings. It seems that the XMLBeans Builder generated code doesn't compile against ... XMLBeans itself ? It that possible ? Any workaround ? Many thanks in advance, Nico