I'm quite new at programming in Java and I've encountered something I don't really understand:
if (Object.getSomething() != null) {
Long Size= null != Object.getSomething().getSomething2()
? Object.Something().getSomething2() : null;
I've been looking for the answer but I can't understand this way of defining a new variable, I mean, the '?' and the ': null' are the things I can't understand.
Ternary conditionals take the following form:
condition ? value_if_true : value_if_false
Consider for instance the mathematical max function. Using regular conditional statements we could write:
int max = 0;
if (a > b) {
max = a;
} else {
max = b;
}
We can do the exact same thing using a ternary condition:
max = a > b ? a: b;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With