简体   繁体   中英

generating import using Jcodemodel

I am trying to generate java code using Jcodemodel.

  1. How to generate required import statements using Jcodemodel?

  2. How to automatically generate the implementation of interface methods when a class implements the interface?

    eg:

     interface Act { void act(); } 

    using Jcodemodel, how to generate the interface method in implementation class? whether do I need to write method using JMethod? Is there any other way to auto generate the implementation methods?

  3. How to generate required imports for a class?

Kindly,guide me

You should use the method

JClass importedClass= codeModel.ref("example.com.impl.MyClass");

And make sure example.com.impl.MyClass is in your classpath. In the generated java source, the import example.com.impl.MyClass statement will be automatically added for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM