What is the Java ?: operator called and what does it do?

前端 未结 16 1753
轮回少年
轮回少年 2020-11-21 05:27

I have been working with Java a couple of years, but up until recently I haven\'t run across this construct:

int count = isHere ? getHereCount(index) : getAw         


        
16条回答
  •  情话喂你
    2020-11-21 06:06

    It's the conditional operator, and it's more than just a concise way of writing if statements.

    Since it is an expression that returns a value it can be used as part of other expressions.

提交回复
热议问题