Java反射:通过输入其名称获取给定类的实例? [英] Java Reflection: get instances of a given class found by entering its name?

查看:94
本文介绍了Java反射:通过输入其名称获取给定类的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能通过以字符串的形式输入类的所有实例吗?

Is it possible to get all instances of a class by entering this class's name as a string?

这样的东西吗?

var instances = Reflection.findClass("com.someone.MyClass").getInstances();

感谢任何反馈。谢谢。

推荐答案

不,没有可用的。如果你挂接调试API,你可以这样做,但不能正常运行。

No, there's nothing like that available. If you hook into the debugging API you may be able to do it, but not when running "normally".

这篇关于Java反射:通过输入其名称获取给定类的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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