是否有一般的“后端” Java反思库 [英] Is there a general "backend" library for Java reflection

查看:131
本文介绍了是否有一般的“后端” Java反思库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java中实现的专门的,解释性的编程语言。作为语言的一小部分,我想添加调用Java的能力。在我深入思考所有的反思之前,我想知道有没有人知道一个通​​用的库来反映Java代码的后端部分。






  • 自动选择基于参数类型的正确方法(如一个智能Class.getDeclaredMethod())

  • 处理数组和普通对象引用之间的区别

  • etc



我花了一点时间来看看动态语言在JVM上的实现,但这些通常比我' m / p>

另一种选择是将我的语法转换为一些动态语言的字符串,并用Rhino或其他东西调用它,但是这比我正在寻找更多的开销。



谢谢!

解决方案>

只是你自己的回答的评论;实际上,beanutils支持获得一个紧密匹配给定一组参数。请参阅 getMatchingAccessibleMethod()



BeanUtils非常强大,具有很多实用方法用于检查班。构造函数自然可以使用相同的支持。


I'm currently working with a specialized, interpreted, programming language implemented in Java. As a very small part of the language, I'd like to add the ability to make calls into Java. Before I dive into all of the nitty-gritty of reflection, I was wondering if anyone knew of a general library for doing the "backend" part of invoking Java code reflectively.

That is, I parse a string (I define the grammar) into some data structure that represents a Java method call (or constructor, or field access) and then pass that data structure to this library that invokes the call and returns the result. In particular, I'd like it to already handle all the edge cases that I don't want to figure out:

  • Automagically pick the right method based on the types of arguments (like an intelligent Class.getDeclaredMethod())
  • Handle distinction between arrays and normal object references
  • etc

I've spent a little time looking at the implementations of dynamic languages on the JVM, but these are generally much more complicated than I'm looking for, or highly optimized for the particular language.

Another option is to convert my grammar into a string in some dynamic language and invoke it with Rhino or something, but that's a little more overhead than I'm looking for.

Thanks!

解决方案

Just a comment to your own answer; actually beanutils has support for getting "a close match" given a set of parameters. See getMatchingAccessibleMethod()

BeanUtils is really powerful and has lots of utility methods for inspecting classes. The same support is naturally available for constructors.

这篇关于是否有一般的“后端” Java反思库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆