0

So this looks like a fancy way of using an if statement to check if bom.getCharsetName() actually returns a valid character set name. However, it is quite confusing and I've never seen this syntax before. How does this break down piece by piece?

String charsetName = bom == null ? defaultEncoding : bom.getCharsetName();
rocksNwaves
  • 5,331
  • 4
  • 38
  • 77
  • 2
    Does this answer your question? [What is a Question Mark "?" and Colon ":" Operator Used for?](https://stackoverflow.com/questions/10336899/what-is-a-question-mark-and-colon-operator-used-for) – sleepToken Feb 11 '20 at 17:13
  • 1
    Just Java's version of a ternary condition. – sleepToken Feb 11 '20 at 17:13
  • If bom is null, use defaultEncoding, if not, use `bom.getCharsetName()` for `charsetName`'s value – gabriel.hayes Feb 11 '20 at 17:13
  • Those duplicates are not satisfactory IMO, because they don't explain the return value of an assignment as well. – Tim Biegeleisen Feb 11 '20 at 17:14
  • @TimBiegeleisen And why does this matter? There´s no assignment in neither of the two operands. Only the return-value of the ternary operator is assigned, which is a pretty normal assigment, nothing special about this. – MakePeaceGreatAgain Feb 11 '20 at 17:14

0 Answers0