我需要生成一个必须有一个返回同一个对象的方法的类。
我想生成这样的东西
public class A{ public A method1(){ ... } }问题是我必须传递方法返回的类的Class对象。 如果我这样做,因为我的类还没有构建,我将得到一个ClassNotFoundException。 有没有办法实现这个目标?
谢谢。
I need to generate a class which must have a method that returns an object of the same class.
I want to generate something like this
public class A{ public A method1(){ ... } }The problem is that I have to pass the Class object of the class being returned by the method. If i do that, because my class is not built yet I will get a ClassNotFoundException. Is there a way of achieving this?
Thanks.
最满意答案
经过一番挖掘后,我设法找到了解决方案。 如果您无法访问类,因此无法提供其对应的Class对象,请使用Codemodel对象中的directClass(String className)方法,该方法将表示类名的String作为输入,并返回相应的JClass对象。
After a little digging I managed to find the solution. If you do not have access to a class and thus you cannot provide its corresponding Class object, use the method directClass(String className) from Codemodel object which takes as input a String representing the class name and returns the corresponding JClass object.
更多推荐
class,method,ClassNotFoundException,电脑培训,计算机培训,IT培训"/> <meta name
发布评论