Why is my use of the ?: conditional operator incorrect?

前端 未结 4 859
广开言路
广开言路 2021-01-22 07:09

I get a compilation error while trying to compile, \"not a statement\", and the code is:

(checkDatabaseExist())?connectToDB() : buildDB();

when

4条回答
  •  无人及你
    2021-01-22 07:27

    The ternary operator can not be used with methods/operations returning void.

    The methods/expressions must return a value compatible with the reference type.

提交回复
热议问题