Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 382
John Evans Avatar asked Aug 24 '12 16:08

John Evans


1 Answers

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. http://www.bracha.org/mirrors.pdf (academic paper, tough going)
  2. http://www.hpi.uni-potsdam.de/hirschfeld/events/past/media/100105_Bracha_2010_LinguisticReflectionViaMirrors_HPI.mp4 (a video, pre-Dart, discusses earlier Mirror systems)
  3. http://gbracha.blogspot.com/2010/03/through-looking-glass-darkly.html (an old, pre-dart, blog post of mine on mirrors)
  4. http://www.wirfs-brock.com/allen/posts/228 (Allen Wirfs-Brock's blog. Allen was a mirror pioneer back in Smalltalk in the 90s)
  5. http://www.wirfs-brock.com/allen/posts/245

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

like image 155
Gilad Bracha Avatar answered Sep 29 '22 06:09

Gilad Bracha