🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #711

A question about inner classes

#711
From: Carlos Zin
Date: Thu, 02 Dec 2004 23:41
28 lines
1922 bytes
Please suppose I have the following case where Tool is a class defined 
somewhere else:

public class ToolFactory {

    private class A extends Tool {}

    private class B extends Tool {}

    public static Tool makeTool(String toolName) {
        if (toolName == "A")
            return new A();
        else if (toolName == "B")
            return new B();
        else
            return null;
    }
}

I am trying to build a static factory method named "makeTool()" which 
produces instances of classes A and B but the compiler complain telling that 
non-static variable this cannot be referenced from a static context.

Making the method non-static eliminate the error but then I need to make an 
instance of Toolfactory in order to access method makeTool(s) which is not 
what I want. I need to call "ToolFactory.makeTool(s)", i.e. a static method 
with no object instance.
How can I solve this problem?
Technical Details
Message-ID: <41afa7d8$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!peer-uk.news.demon.net!kibo.news.demon.net!demon!194.74.65.66.MISMATCH!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,8b4c0601b22a435f
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Carlos Zin" <nomailplease@hotmail.com>
Newsgroups: borland.public.jbuilder.java.language
Subject: A question about inner classes
Date: Thu, 2 Dec 2004 19:41:23 -0400
Lines: 31
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 200.109.212.207
Message-ID: <41afa7d8$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1102030808 200.109.212.207 (2 Dec 2004 15:40:08 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!peer-uk.news.demon.net!kibo.news.demon.net!demon!194.74.65.66.MISMATCH!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail