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

前端 未结 14 2328
萌比男神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 09:14

    Void is not a real type. Void is just a place holder to make syntax of methods definition more consistent. This is not the java innovation; this is inherited from C.

    This is the reason that compiler does not allow you to write return cancel() even if method cancel() is void.

提交回复
热议问题