Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30630
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!.POSTED!not-for-mail |
|---|---|
| From | Patrick Roemer <sangamon@netcologne.de> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Why base class's static method shows up in derived class? |
| Date | Mon, 05 Jan 2015 13:07:33 +0100 |
| Organization | news.netcologne.de |
| Lines | 36 |
| Distribution | world |
| Message-ID | <m8duq6$cim$1@newsreader4.netcologne.de> (permalink) |
| References | <e8dd9f53-8064-4e8b-bedf-809bddecfe8c@googlegroups.com> |
| NNTP-Posting-Host | xdsl-78-34-154-151.netcologne.de |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | newsreader4.netcologne.de 1420459654 12886 78.34.154.151 (5 Jan 2015 12:07:34 GMT) |
| X-Complaints-To | abuse@netcologne.de |
| NNTP-Posting-Date | Mon, 5 Jan 2015 12:07:34 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.24) Gecko/20100411 Thunderbird/2.0.0.24 Mnenhy/0.7.6.0 |
| In-Reply-To | <e8dd9f53-8064-4e8b-bedf-809bddecfe8c@googlegroups.com> |
| Xref | csiph.com comp.lang.java.programmer:30630 |
Show key headers only | View raw
Responding to Stone Zhong:
> With the code snipped below:
>
> for (Method method: HttpClientContext.class.getMethods()) {
> if (method.getName().equals("create")) {
> System.out.printf("%s%n", method);
> }
> }
>
>
> I got output:
> public static org.apache.http.client.protocol.HttpClientContext org.apache.http.client.protocol.HttpClientContext.create()
> public static org.apache.http.protocol.HttpCoreContext org.apache.http.protocol.HttpCoreContext.create()
>
>
> HttpClientContext derived from HttpCoreContext. Both class has a static
> method "create" with no parameter.
>
> Why HttpCoreContext.create shows up as HttpClientContext's method? I am
> expecting only "public static org.apache.http.client.protocol.HttpClientContext
> org.apache.http.client.protocol.HttpClientContext.create()" to show up,
> am I missing anthing?
Class#getMethods() returns (public) methods inherited from superclasses
and interfaces as well. Static methods from direct superclasses are
inherited just as instance methods. So in general it's fine that static
methods of the superclass show up in the output of #getMethods().
What puzzles me in this specific case is that both methods have the same
signature. To my understanding, according to JLS8 ยง8.4.8, the
superclass' #create() method should not be inherited because of the
subsignature relationship...
Best regards,
Patrick
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why base class's static method shows up in derived class? Stone Zhong <stone.zhong@gmail.com> - 2015-01-04 23:52 -0800 Re: Why base class's static method shows up in derived class? Patrick Roemer <sangamon@netcologne.de> - 2015-01-05 13:07 +0100 Re: Why base class's static method shows up in derived class? v_borchert@despammed.com (Volker Borchert) - 2015-01-05 22:12 +0000
csiph-web