Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30630

Re: Why base class's static method shows up in derived class?

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 2015-01-05 13:07 +0100
Organization news.netcologne.de
Message-ID <m8duq6$cim$1@newsreader4.netcologne.de> (permalink)
References <e8dd9f53-8064-4e8b-bedf-809bddecfe8c@googlegroups.com>

Show all headers | 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


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