如何在super关键字中使用具有多个条件的三元运算符?

问题描述 投票:0回答:1

我试图使用超级构造函数和三元运算符将以下代码转换为一行代码。尝试过多种东西但没有任何效果。

if (c == 0) {
    super(Piece.JMAN, x, y, Color.red);
} else if (c == 1) {
    super(Piece.JMAN, x, y, Color.green);
} else {
    super(Piece.JMAN, x, y, Color.yellow);
}
java ternary-operator
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.