How to get concrete object of a static method via mirror API?


I have something like this:

class MyClass
   static void DoSomething(arg1, arg2){...}

Via reflection, I am able to get the ClassMirror of this class. From this point, how would I get to the concrete static function so I can call it.

Note that I tried to use:

ObjectMirror.invoke('DoSomething', [arg1, arg2]); 

which would initially appear to work, but it doesn’t support passing of complex types as arguments, This static function requires a complex type as one of it’s arguments.

Ideally, I’d like to get the ‘Function’ object that represents the static method so I can invoke it directly.


a. The current state of affairs is temporary. The plan is that the mirror API will wrap the arguments with mirrors for you.

b. The API may eventually support a getProperty method that will give you a Future on the function object. However, you will not get a Function object directly, so this won’t really make any difference in this case.

c. The core idea is that the API fundamentally works on mirrors. To make it more usable, it should accept non-mirrors as input and wrap them in mirrors for you. It will always return mirrors, and in some cases return futures on these. This is so the API works the same for remote and local cases.

d. Resources for understanding mirrors:

  1. (academic paper, tough going)
  2. (a video, pre-Dart, discusses earlier Mirror systems)
  3. (an old, pre-dart, blog post of mine on mirrors)
  4. (Allen Wirfs-Brock’s blog. Allen was a mirror pioneer back in Smalltalk in the 90s)

You can also search my blog, or Allen Wirf-Brock’s for posts on the topic.

Answered By – Gilad Bracha

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *