john
john

Reputation: 741

Javadoc methods and inherited methods

In javadoc, why is there a separate section for inherited methods? For example in LinkedList, http://docs.oracle.com/javase/1.5.0/docs/api/java/util/LinkedList.html, there is a Method Summary section and a section for inherited methods, like "Methods inherited from interface java.util.List". Some of the method in Method Summary are inherited from other classes so why is there this separate section? How does javadoc decide which methods to put in the Method Summary and which in the inherited section (even when a method in Method Summary is inherited)?

Upvotes: 0

Views: 639

Answers (1)

stacker
stacker

Reputation: 68942

It uses the Reflection-API to decide whether a method is inherited or not.

  • getMethod() returns inherited methods
  • getDeclaredMathod() returns all methods

for further references see also Discovering Class Members

An example that demonstrates the usage of the API

public class Reflect extends ArrayList {
    public static void main(String[] args) {
        Reflect r = new Reflect();
        r.dump();
    }

    private void dump() {
        Method[] methods = this.getClass().getMethods();
        Set<String> ms = new  HashSet<String>();
        for ( Method m : methods ) {  
            ms.add( m.getName() );
        }
        Method[] declMethods = this.getClass().getDeclaredMethods();
        Set<String> ds = new  HashSet<String>();
        for ( Method m : declMethods ) {  
            ds.add( m.getName() );
        }
        for ( String name : ms ) {
            System.out.println(name + " is inherited =" +! ds.contains(name));
        }

    }
}

Upvotes: 1

Related Questions