Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle methods with inaccessible argument types? #21

Open
GoogleCodeExporter opened this issue Jul 3, 2015 · 1 comment
Open

Comments

@GoogleCodeExporter
Copy link

Java cleverly lets you call a method with an inaccessible argument type, by
simply passing null. For example, you may have:

package foo;
class Secret {
}

public class Foo {
    public void foo (Secret s) { ... }
}

package bar;
public class Bar {
    public void callFoo () {
        new Foo().foo(null);
    }
}

which is totally legal code. It is impossible for Bar to create an instance
of Secret, but it can pass null.

Now for the problem. We convert the foo() call into:

  RT.invoke("foo", new Class<?>[]{ Secret.class }, new Foo())

which references Secret.class by name and thus does not compile. Sigh.

Original issue reported on code.google.com by [email protected] on 17 May 2010 at 2:42

@GoogleCodeExporter
Copy link
Author

Just to underscore that this is wacky. Replacing the body of callFoo() with the
following results in compilation failure: new Foo().foo((Secret)null).

Original comment by [email protected] on 17 May 2010 at 2:43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant