I get a compilation error while trying to compile, “not a statement”, and the code is:
(checkDatabaseExist())?connectToDB() : buildDB();
when the functions are:
private boolean checkDatabaseExist() {...}
private void connectToDB(){...}
private void buildDB(){...}
any ideas?
Yes, you can’t use the conditional operator like that. It’s intended to compute one expression or another as a result. It’s not intended to be a way of choosing one statement to execute or another.
Just use: