Static method access

72 views
Skip to first unread message

Frederik De Bleser

unread,
Jan 29, 2013, 2:00:22 PM1/29/13
to reflecta...@googlegroups.com
Hi,

Is it possible to access a static method? Both MethodAccess.getIndex and MethodAccess.invoke with a name argument throw an "Unable to find method" exception.

Here's an example:

    public class App {

        public static void printHello() {
            System.out.println("Hello!");
        }

        public static void main(String[] args) {
            MethodAccess access = MethodAccess.get(App.class);
            int methodIndex = access.getIndex("printHello");
            access.invoke(null, methodIndex);
        }

    }


Kind regards,

Frederik

Nate

unread,
Feb 6, 2013, 10:14:06 AM2/6/13
to reflecta...@googlegroups.com
Hi Frederik,

Sorry I missed your message. No, currently MethodAccess does not provide access to static methods. See the code:

if (Modifier.isStatic(modifiers)) continue;

I would accept a patch though! :)

-Nate


--
--
You received this message because you are subscribed to the "reflectasm-users" group.
http://groups.google.com/group/reflectasm-users
---
You received this message because you are subscribed to the Google Groups "reflectasm-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reflectasm-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages