Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:50:45+00:00 2026-05-17T22:50:45+00:00

According to http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html#getDeclaredMethods%28%29 , Class.getDeclaredMethods() should only include methods declared by the class. However,

  • 0

According to http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html#getDeclaredMethods%28%29, Class.getDeclaredMethods() should only include methods “declared by the class”. However, I am getting some pretty surprising results with the test code below:

import java.util.Arrays;

class A {
 public static A m1() { return null; }
 public static A m2() { return null; }
 public static A m3() { return null; }
}

class B extends A {
 public static A m1() { return null; }
 public static B m2() { return null; }
// public static Object m3() { return null; } won't compile
}


public class Scratch {
 public static void main(final String[] args) {
  System.out.println(Arrays.asList(B.class.getDeclaredMethods()));
 }
}

A few things that look quite strange/surprising to me:

  • The compiler complain about B.m3() having an incompatible return type with A.m3(). This is dictated by JSL 8.4.8.3 (Page 225 v3 langspec-3.0.pdf). But I am curious, why this restriction needs to apply to static methods. My understanding is that static methods can be hidden and not overriden, and that the reference is resolved at compile time, so what is the reasoning behind this restriction?

  • Two m2() methods are included in the output. This appears to contradict the claim that getDeclaredMethods() only returns methods “declared by the class”, and “excludes inherited methods”. I don’t see A.m2() as “declared by” B.

  • One m1() is included in the output. Following the previous point, if it made sense to let getDeclaredMethods() return two m2(), why doesn’t it return two m1() as well? They are after all two distinct methods, and one is hidden by the other. I don’t see any fundemental difference between the case of m1() and m2() except the return type being the same in the case of m1(), but the return type as I understand is not part of the method signature?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:50:45+00:00Added an answer on May 17, 2026 at 10:50 pm

    See https://bugs.java.com/bugdatabase/view_bug?bug_id=6815786

    Though it had been reported against 1.6.0_12-b04 on 2009-03-11 05:44:57.0
    but Sun accepted it on 2010-07-22 01:25:56.0

    in brief:

    Synopsis (reflect) Class.getDeclaredMethods() is returning inherited methods

    Category java:classes_lang

    Reported Against

    State 3-Accepted, bug

    Priority: 3-Medium

    Submit Date 11-MAR-2009

    Work Around N/A

    Evaluation Will investigate.

    Posted Date : 2010-07-22 01:25:56.0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to google and some other sources (e.g., http://www.enterprisedt.com/publications/oracle/result_set.html ), if I want to
First off, according to http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx , the List.Find method is only listed as throwing
According to this http://perldoc.perl.org/UNIVERSAL.html I shouldn't use UNIVERSAL::isa() and should instead use $obj->isa() or
According to this http://www.cplusplus.com/reference/clibrary/csignal/signal.html SIGINT is generally used/cause by the user. How do i
According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use
According to http://msdn.microsoft.com/en-us/library/aa916070.aspx (DnsQuery_W), DNS query libraries are available on Windows Mobile / CE
According to this: http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&referringTitle=IronPython%20Performance IronPython (Python for .Net) is faster than regular Python (cPython)
According to this discussion , the iphone agreement says that it doesn't allow loading
According to the manual , git dcommit will create a revision in SVN for
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.