Can we use command in ternary operator (Java)?

后端 未结 2 1178
野的像风
野的像风 2021-01-29 13:05

This is a working code:

String a = \"first\";
String b = \"second\";
String object;
System.out.println(object != null ? a : b);

But it isn\'t:<

2条回答
  •  一个人的身影
    2021-01-29 14:04

    The ternary operator should always return a value, whereas in case of SysOut the return type is void.

提交回复
热议问题