About Question enthuware.ocpjp.i.v11.2.1408 :
Posted: Wed Dec 11, 2019 12:19 pm
I read "...+ operator is not overloaded for anything except String". Well, why "System.out.println(true + "hello" + 3); " is fine?
Jshell console:
jshell> /open C:\WSs\to-learn\deleteLater.java
truehello3
| Error:
| bad operand types for binary operator '+'
| first type: int
| second type: boolean
| System.out.println(2 + (2 >= 2) + 3);
| ^----------^
| Error:
| bad operand types for binary operator '+'
| first type: int
| second type: boolean
| System.out.println(2 + true + "hello" + 3);
| ^------^
jshell>
System.out.println(true + "hello" + 3); //fine
System.out.println(2 + (2 >= 2) + 3); //exception
System.out.println(2 + true + "hello" + 3); //exception
Jshell console:
jshell> /open C:\WSs\to-learn\deleteLater.java
truehello3
| Error:
| bad operand types for binary operator '+'
| first type: int
| second type: boolean
| System.out.println(2 + (2 >= 2) + 3);
| ^----------^
| Error:
| bad operand types for binary operator '+'
| first type: int
| second type: boolean
| System.out.println(2 + true + "hello" + 3);
| ^------^
jshell>