>> Don't you get a problem here that you try to make a static reference to a
>> non-static variable? 'instance' is non-static... 'getInstance' is static.
>
>There's no requirement that a static function return a reference to
>static, it can return anything it wants.
>

No, it can't. A static method can't return an object that only exists if the
'outer'
object exists.

class A {
    private B b;

    public static B get () {
        return b;
    }
}


The method 'get' can be called without the existance of an actual A object,
by simply
calling "A.get ();".   However, the private B object exists only if there is
an A object. How
can B be returned in "A.get ();" when A does not exist?
The only way this works is if B is static too. So instead of 'private B b'
it should be
'private static B b'.

Btw, I just tested it 'cause I was about to implement a Singleton in the
project I'm
working on.

Arjan Houtman
Antares Informatisering
[EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to