如何通过Java反射动态创建Java类? [英] How to create Java classes Dynamically by Java Reflection?

查看:876
本文介绍了如何通过Java反射动态创建Java类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反射用于加载java类类,并在运行时对它们进行操作。但是我遇到了一个奇怪的问题,问我如何通过Reflection即时创建Java类。我的意思是类没有被编译或有源代码,直到我们想要它们被创建。真的有可能吗?任何示例?

解决方案

您可以尝试ASM
ASM



或字节代码工程库



< a href =http://commons.apache.org/bcel/ =nofollow noreferrer>字节代码工程库



用于操纵,在运行时创建课程



在.NET中,我们有Reflection.Emit(C#),它可以做到
Reflection.Emit



不知道是否有直接java等效
您可以在此处看到另一个类似的问题:与...相当的反思。 >


Reflection is used to load java class classes and manipulate them on the fly. But I have across a weird question that is asking me how to create Java classes on the fly by Reflection.I mean the classes is not compiled or have source code till we want them created. Is it really possible? Any examples?

解决方案

You can try ASM ASM

or Byte code engineering library

Byte code engineering library

for manipulating, creating classes at run time

In .NET we have Reflection.Emit(C#) which can do that Reflection.Emit

Not sure whether there is a direct java equivalent. You can see another similar question on SO here Java equivalent of reflection.emit

这篇关于如何通过Java反射动态创建Java类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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