i discovered a strange behavior in HashMap using Eclipse 4.7.2.
The following line seems correct for me:
infos.containsKey("desc") ? stmt.setString(8, infos.get("desc")) :
stmt.setString(8, "No description");
infos is type of HashMap<String, String> and a PreparedStatement should be filled with the value of the description (desc) field in the map.
But instead of just doing what is written there Eclipse indicates that in this line are multiple errors:
infos.containsKey**("desc")** ? stmt.setString(8, infos.get("desc")) :
stmt.setString(8, "No description"**)**;
I marked the characters which are underlined in Eclipse.
The error message is:
Multiple markers at this line
- Syntax error on token ")", delete this token
- Syntax error, insert ")" to complete Expression
- Type mismatch: cannot convert from String to
boolean
The function of the ? operater is rather clear but the behavior is unclear.
Does anyone can show me where I am wrong or how to aviod this error.
Thank you!