Why can't I explicitly return void from a method?

前端 未结 14 2335
萌比男神i
萌比男神i 2021-01-01 08:23
void run() {
    ...
    if (done) return cancel();
    ...
}

where cancel() return void. This won\'t compile... and I ca

14条回答
  •  遥遥无期
    2021-01-01 08:47

    void is not a type. If you use the Void type instead of the void keyword, however, your code will work, but: You'll manually have to return null in all exit points from your method.

提交回复
热议问题