lundi 21 mars 2016

Is Method.invoke broken in java8?

I just created the following minimalistic testcase:

package testcase;

public class Main
{

    public static void main( String[] args )
        throws Throwable
    {
        if ( args.length == 0 )
            Main.class.getMethod( "main", String[].class ).invoke( null, new String[] { "test" } );
    }

}

It should just run, with no output and no exception. The main method should be calling itself using reflection. However I get the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at testcase.Main.main(Main.java:10)

And I cannot figure out, why...





Aucun commentaire:

Enregistrer un commentaire