Article View: borland.public.jbuilder.java.language
Article #8296Re: use override method string.replace
From: John McGrath TeamB
Date: Thu, 29 Mar 2001 08:43
Date: Thu, 29 Mar 2001 08:43
41 lines
1997 bytes
1997 bytes
On Wed, 28 Mar 2001 16:30:46 +0800, Stephen Zeng wrote:
> class Class {
>
> static String replace(String str, String pattern, String replace) {
> ....}
>
> String s="";
> s.replace(s,"//:","package c");
>
> }
> I write a method and want to override the String.replace method in
> my class.
>
> How to use the override method? s.replace can not use the override
> method.
In order to override a method in a given class, you would have to
create a subclass of that class, and then define a method in the
subclass that has the exact same signature as the method defined
in the superclass.
However, the String class is declared "final", which means that you
cannot extend it.
It looks like you are really just trying to write a utility method in
your class that works on Strings, and there is no problem with that.
But you reference your replace() method as a String member class, and
that is not correct. From what you posted, it looks like you could
simply change the call to:
replace(s,"//:","package c");
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<MPG.152c9ec1e05674e698a0ce@forums.borland.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!newsfeed1.uni2.dk!newssuck.uni2.dk!dnews!209.92.40.60References:
<3ac1a1e3_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1bdd43767313d6d7 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-29 00:52:41 PST From: John McGrath [TeamB] <ng-b@JPMcGrath.net> Newsgroups: borland.public.jbuilder.java.language Subject: Re: use override method string.replace Date: Thu, 29 Mar 2001 03:43:55 -0500 Message-ID: <MPG.152c9ec1e05674e698a0ce@forums.borland.com> References: <3ac1a1e3_1@dnews> X-Newsreader: MicroPlanet Gravity v2.30 NNTP-Posting-Host: 209.92.40.60 X-Trace: 29 Mar 2001 00:39:25 -0800, 209.92.40.60 Lines: 41 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!newsfeed1.uni2.dk!newssuck.uni2.dk!dnews!209.92.40.60