Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

What Do Two Question Marks in a Row in a Ternary Clause Mean?

It is simply a nested ternary statement. Clearer by adding parentheses:

number == null ? (required ? 1 : 2) : 3;

what would the inputs need to be for 2 to be returned?

number = null and required = false


This is why it’s always a good idea to explicitly add parentheses, so the intent is clear at a glance :

Integer val = number == null ? (required ? 1 : 2) : 3;

Tags:

Java

Conditional Operator

Ternary

Related

The command, pip install --upgrade pip, install all version of pip Empty braces magic in initializer lists Is the order of writes to separate members of a volatile struct guaranteed to be preserved? How to add Android Kotlin files to a Cordova Plugin project C++17 static template lazy evaluation Are left out fields by C++ 20 designated initialization guaranteed to be zero initialized? Does Rust devirtualize trait object function calls? Why do `join` and/or `JSON::to_json` convert my data silently from integer to string? How can I use Java Stream to find the average of all values that share a key? Strange default empty constructor on a virtual inheritance behaviour on GCC Can I delete a field in awk? Is the initialization order of the vector elements guaranteed by the standard?

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy