创建一个方法,返回我想在Codemodel中生成的类(Create a method which returns the class that i want to generate in Codemo

编程入门 行业动态 更新时间:2024-10-28 15:20:59
创建一个方法,返回我想在Codemodel中生成的类(Create a method which returns the class that i want to generate in Codemodel)

我需要生成一个必须有一个返回同一个对象的方法的类。

我想生成这样的东西

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

本文发布于:2023-07-30 11:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我想   创建一个   方法   Codemodel   Create

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!