Why can't I throw an exception while using the ternary operator

前端 未结 4 1077
南旧
南旧 2021-02-13 03:49

This doesn\'t compile and gives the following error : Illegal start of expression. Why?

public static AppConfig getInstance() {
        return mConf         


        
4条回答
  •  清歌不尽
    2021-02-13 04:15

    You are trying to return a throw new RuntimeException("error"). That is why you are getting error. Because in true case you are returning AppConfig and in false case you are returning exception.

提交回复
热议问题