I am using reflection APIs to do some queries on Java methods. Below is the code snippet to find out the return type of calling, say new java.lang.StringBuilder().append('a')
:
Class<?> c = Class.forName("java.lang.StringBuilder");
Method[] mList = c.getMethods();
for (int i = 0; i < mList.length; i++) {
if (mList[i].getName() == "append"
&& mList[i].getParameterTypes().length == 1
&& mList[i].getParameterTypes()[0].getCanonicalName() == "char") {
System.out.println(mList[i]);
}
}
Oddly, the output gives
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 gives StringBuilder
as the return type. Does that mean the method append
actually overloads on return type?
Aucun commentaire:
Enregistrer un commentaire