1

Is it possible to use the ternary operator in code generated by com.sun.codemodel?

I wish to generate the following statement:

this((A==null)?A.getSomething:null)
skaffman
  • 398,947
  • 96
  • 818
  • 769
Nacha
  • 107
  • 1
  • 5

1 Answers1

4

com.sun.codemodel.JOp.cond should already generate a ternary operator. See the source:

public static JExpression cond(JExpression cond, JExpression ifTrue, JExpression ifFalse) {
     return new TernaryOp("?", ":", cond, ifTrue, ifFalse);
}
Richard Campbell
  • 3,591
  • 23
  • 18