Thanks that is the correct answer for "static inner class".
With ordinary non-static inner class there is a hidden reference to
the outer class. Declaring an inner class static removes this hidden
reference. The static inner class becomes referable in global scope
with having to refer to an outer class. However a static inner class
cannot have it self a static inner class.
Static inner class
1) can be refered to without regard to the outer class. That is you do
not to instantiated the outer class to instantiate an inner class.
2) cannot refer to any member or method belonging to the outer class.
public class AppFrame extends JFrame {
public static SwitchPLAFAction {
private LookAndFeelInfo lfi;
private JFrame frame;
SwitchPLAFAction( LookAndFeelInfo lfi, JFrame frame )
{ this.lfi = lfi; this.frame = frame )
...
}
public static void main( String[] args )
{
AppFrame appFrame = new AppFrame( ... );
...
// Now to need to refer to a AppFrame object!!!!
SwitchPLAFAction plafAction =
new SwitchPLAF( MyLookAndFeel, appFrame );
//
// Normal inner class instantion
// SwitchPLAFAction plafAction =
// appFrame.new SwitchPLAF( MyLookAndFeel, appFrame );
//
//
}
}
Thanks Pavel for putting me straight.
Pete
"Finito!"
______________________________ Reply Separator _________________________________
Subject: Re: Java language question: static classes ?
Author: paul ([EMAIL PROTECTED]) at lon-mime
Date: 16/10/98 16:14
> So public static SwitchPLAFAction { ... } is a just java object class
> that is really instantied just once, like some sort of singleton?
No, no. I did not mean that static classes are related to singletons.
They are not AFAIK.
> Actually I have used a modified version of the ActionEvent class from
> Kim Topley "Core JFC" example in Xsql as an inner class. So now Xsql c
an
> switch PLAFs too. It works, but I still dont understand public static class ?
This is an example of what I want to say:
// --------File A.java
public class A {
...
public class B { ... }
}
// --------End of file
// --------File C.java
public class C {
...
public static class D { ... }
}
// --------End of file
You can use both classes A.B or C.D in any packages such as both of them
are public. But A.B class has one additional hidden member of A class
and requires one additional constructor parameter of A type (in default
"no-arg" constructor) if you create it outside of A class scope. C.D
class is just like usual Java top level public class.
That's all I know about static classes
Hope this will help.
Pavel
// --------
>
> I cant find a reference to it in "Exploring Java". I will see if I can
> borrow back "Core Java" this weekend.
>
> Pete
..
> Correct me if I'm wrong, but I do not believe top-level classes can have
> the 'static' modifier applied, but if you want a shared entity, do
> something like this:
>
> public class DefaultFactory
> extends AbstractFactory
> {
> protected DefaultFactory() { /* empty */ } // or private if you wish
> public final static DefaultFactory SHARED_INSTANCE = new
> DefaultFactory();
> ...
> }
>
> This is how I create shared entities (for example in JUMP, a framework for
> numeric computations). The only potential problem you have here is
...