Java Single Conditional Operator

Aaron Scott-Boddendijk talden at gmail.com
Tue Aug 23 19:49:09 UTC 2022


Using a more idiomatic use of whitespace, isn't this just the difference
between:

|    if (a > 50) print("50 more");

and

|    a > 50 ?. print("50 more");

That is, a two character difference for a new operator we can't use for
something else (and that operator is highly recognisable as the 'null-safe
navigation' operator in several languages - and proposed for Java way back
in Java 6/7 days with Project Coin - or was it even earlier than that).

If teams want to shorten code in this form, can't they just change
formatting policies to allow a single-branch, single-statement body,
if-statement to occupy a single line?

--
Aaron Scott-Boddendijk


On Wed, Aug 24, 2022 at 6:29 AM sankar singh <sankar.singu at gmail.com> wrote:

> Hi Team,
>
> We are using ternary operator
>
> Can we use single conditional code like the below.
>
> *if (a>50)*
> *   print("50 more")*
>
> *a>50?.  print("50 more")*
>
>
> --
>
> regards,
>
> Shankar.S
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20220824/05d8a8f5/attachment.htm>


More information about the amber-dev mailing list