Thursday, 15 August 2013

java - reflection api give overloading on function's return type -


I am using reflection API to question some Java methods. The code snippet to find out the calling calling given below is new java.lang.StringBuilder (). Addend ('a') :

  class & lt; ? & Gt; C = Class.forName ("java.lang.StringBuilder"); Method [] mList = c.getMethods (); For (int i = 0; i & lt; mList.length; i ++) {if (mLISISIS [i] .getName () == "append" & amp; mList [i] .getParameterTypes (). Length = = 1 & amp;; and MLIF [i] .getParameterTypes () [0] .getCanonicalName () == "four") {System.out.println (mList [i]); }}  

Strangely, returns output

public java.lang.AbstractStringBuilder java.lang.StringBuilder.append (char)

Public java.lang.Appendable java.lang.StringBuilder.append (char) throws java.io.IOException

public java.lang.StringBuilder java.lang.StringBuilder.append (char)

While the Java API specification only returns stringbinder as the return type. Does it mean that attach actually overload on the return type?

We have from:

class represented by this class object Or, all the public members of the interface give an array containing method objects reflecting methods, people who have been classified by the class or interface and they have inherited from those superclasses and superfitters. All (public) member methods inherited from the array class object class are returned. Elements are not sorted in the given array and are not in any particular order. This method gives an array of length 0 if this class object represents a class or interface in which no member is a member, or if this class object represents a primitive type or zero.

> AbstractStringBuilder Expands AbstractStringBuilder Applies to Appendable

That's why you find 3 ways


1 comment: