1

是否可以在生成的代码中使用三元运算符com.sun.codemodel

我希望生成以下语句:

this((A==null)?A.getSomething:null)
4

1 回答 1

4

com.sun.codemodel.JOp.cond应该已经生成了一个三元运算符。查看源代码

public static JExpression cond(JExpression cond, JExpression ifTrue, JExpression ifFalse) {
     return new TernaryOp("?", ":", cond, ifTrue, ifFalse);
}
于 2011-07-28T13:54:39.117 回答