Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is very interesting, but it is not Android-specific, I think.</p> <p>I wrote this small test in plain Java:</p> <pre><code> public class ReflectionTest { public static void main(String[] args){ Method[] m = ReflectionTest.class.getDeclaredMethods(); for (Method method : m) { System.out.println(method.getName()); } try { Method m1 = ReflectionTest.class.getDeclaredMethod("d0", int.class, boolean.class); if(m1 != null){ System.out.println("m1 found!"); } } catch (Exception e) { e.printStackTrace(); } try { Method m2 = ReflectionTest.class.getDeclaredMethod("d0", Integer.TYPE, Boolean.TYPE); if(m2 != null){ System.out.println("m2 found!"); } } catch (Exception e) { e.printStackTrace(); } try { Class&lt;?&gt;[] carr = m[1].getParameterTypes(); Method m3 = ReflectionTest.class.getDeclaredMethod("d0", carr); if(m3 != null){ System.out.println("m3 found!"); } } catch (Exception e){ e.printStackTrace(); } } public void d0(int a, boolean b){ } } </code></pre> <p>In eclipse, if I debug it, the three m1,m2 and m3 are printed. However, if I run it, a <code>NoSuchMethodException</code> is thrown when trying to get m3.</p> <p>UPDATES:</p> <ul> <li>Tested running with jre 7 under linux, and all three m1,m2 and m3 were printed. Perhaps is a problem with jre6? Or is eclipse run configuration?</li> <li>Changed <code>carr</code> declaration to use method 0 instead of 1: <code>Class&lt;?&gt;[] carr = m[0].getParameterTypes();</code> as Gray suggested. Now it runs ok but throws exception in debug mode. This means different method order for the returned array <code>m</code>.</li> <li>Update #2 confirmed, I've included a for loop to print the method names. In run mode the order of the method array is reversed compared to debug mode.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload