Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
| creating:jlists [2025/11/03 23:23] – Use ternary operator ahelwer | creating:jlists [2025/11/04 17:32] (current) – Further simplified instanceof code ahelwer | ||
|---|---|---|---|
| Line 355: | Line 355: | ||
| List< | List< | ||
| for (Expr junct : juncts) { | for (Expr junct : juncts) { | ||
| - | Expr.Variadic vjunct; | + | |
| - | if ((vjunct = asVariadicOp(op, | + | && |
| flattened.addAll(vjunct.parameters); | flattened.addAll(vjunct.parameters); | ||
| } else { | } else { | ||
| Line 364: | Line 364: | ||
| return new Expr.Variadic(op, | return new Expr.Variadic(op, | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | This uses Java's conditional-assign syntax along with the '' | ||
| - | <code java> | ||
| - | private Expr.Variadic asVariadicOp(Token op, Expr expr) { | ||
| - | return | ||
| - | expr instanceof Expr.Variadic vExpr && vExpr.operator.type == op.type | ||
| - | ? vExpr : null; | ||
| } | } | ||
| </ | </ | ||