Reflection / How do I call a method that accepts an array of Class?

93 views
Skip to first unread message

Daniel Barlow

unread,
Nov 17, 2010, 5:05:19 AM11/17/10
to The Mirah Programming Language
I think I need to call
java.lang.Class.getDeclaredMethod(String,Class[]) from Mirah, but I
can't figure out the syntax for the second argument.

The assumptions that led me to this point:
1) that o.send is purposely not implemented so I need to use the Java
reflection support instead
2) that mirah is close enough to ruby that I stand a reasonable chance
of implementing a DSL to generate Android Layouts and replace the
rather ugly verbose XML stuff in regular android apps. I don't need
instance_eval, but I'm assuming block.yield will work more or less as
it does in ruby

If these assumptions are wrong, please let me know as I don't need the
original question answered in that case ;-)

Actually I have another assumption which I'd be grateful if anyone
could confirm/rebut: that I should not expect to be able to add
methods to Java classes (e.g. if I want to write methods to do things
with strings I will probably have to make them static methods of some
utility class rather than extending java.lang.String directly).

John Woodell

unread,
Nov 17, 2010, 11:40:02 AM11/17/10
to mi...@googlegroups.com
The apparent ability to add new methods to an existing Java class is definitely on the roadmap.

Rib Rdb

unread,
Nov 17, 2010, 5:57:42 PM11/17/10
to mi...@googlegroups.com

-- Sent from my phone


On Nov 17, 2010 11:48 AM, "Daniel Barlow" <daniel....@gmail.com> wrote:
>
> I think I need to call
> java.lang.Class.getDeclaredMethod(String,Class[]) from Mirah, but I
> can't figure out the syntax for the second argument.

classes = Class[1]
classes[0] = String.class

>
> The assumptions that led me to this point:
> 1) that o.send is purposely not implemented so I need to use the Java
> reflection support instead

Well there's no on purpose there.  This probably isn't something we'd add to mirah itself but it should be easy to add this as an extension.   Also if you're using Java 1.7 you can use dynamic types in mirah. I think there's a sample in the examples directory.

> 2) that mirah is close enough to ruby that I stand a reasonable chance
> of implementing a DSL to generate Android Layouts and replace the
> rather ugly verbose XML stuff in regular android apps.  I don't need
> instance_eval, but I'm assuming block.yield will work more or less as
> it does in ruby

Well you can't use yield, but you can achieve the same things using an interface or a macro.  I think there should be an example of using an interface on the mirah.org wiki or this mailing list, but I won't be able to look it up until I finish traveling and get back to a computer.

Reply all
Reply to author
Forward
0 new messages