简体   繁体   中英

JCodeModel method writing, issues with “new”

Need help in converting the following piece of code to jcodemodel understandable format

@Override
    public final void blah() {
XStream xstream = new XStream(new DomDriver());
        String xml = xstream.toXML(this);
}

Any help appreciated.

Never mind... solved it... :)

JBlock block = jtoStringMethod.body();
        JVar line1 = block.decl(xstream, "xstream", JExpr._new(xstream).arg(JExpr._new(domDriver)));
        JVar line2 = block.decl(jmod._ref(String.class), "xml", JExpr.ref("xstream").invoke("toXML").arg(JExpr._this()));
        block._return(JExpr.ref("xml"));

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