๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: A question about inner classes

#716
From: Carlos Zin
Date: Fri, 03 Dec 2004 00:22
67 lines
2930 bytes
Thank you for your help but I tried that sintaxis before with no success, 
still get the same error!
CZ


"Lori M Olson [TeamB]" <javadragon@techie.com> escribi๏ฟฝ en el mensaje 
news:41afa9f3@newsgroups.borland.com...
>
>
> Carlos Zin wrote:
>> 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?
>>
>>
>>
>
> I just ran into this.  It's maddening and embarrassing all at the same 
> time.  You need to use:
>
> return new ToolFactory.A();
> return new ToolFactory.B();
>
> -- 
>
> Regards,
>
> Lori Olson [TeamB]
>
> ------------
>
> Save yourself, and everyone else, some time and search the
> newsgroups and the FAQ-O-Matic before posting your next
> question.
>
> Google Advanced Newsgroup Search
>     http://www.google.ca/advanced_group_search
> Other Newsgroup Searches:
>     http://www.borland.com/newsgroups/ngsearch.html
> Joi Ellis's FAQ-O-Matic:
>     http://www.visi.com/~gyles19/fom-serve/cache/1.html
> 
Technical Details
Message-ID: <41afb160@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!63.218.45.11.MISMATCH!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41afa7d8$1@newsgroups.borland.com> <41afa9f3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,8b4c0601b22a435f
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII
From: "Carlos Zin" <nomailplease@hotmail.com>
Newsgroups: borland.public.jbuilder.java.language
References: <41afa7d8$1@newsgroups.borland.com> <41afa9f3@newsgroups.borland.com>
Subject: Re: A question about inner classes
Date: Thu, 2 Dec 2004 20:22:04 -0400
Lines: 69
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 200.109.212.207
Message-ID: <41afb160@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1102033248 200.109.212.207 (2 Dec 2004 16:20:48 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!63.218.45.11.MISMATCH!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail