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 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: References: 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: Xref: csiph.com comp.lang.java.programmer:30630 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