Skip to main content
2 of 2
added 478 characters in body
JacquesB
  • 62.4k
  • 21
  • 137
  • 190

Some methods, like System.out.println does not return anything useful, but is called purely for this side effect. void is a helpful indicator for the compiler and for the reader of code that no useful value is returned.

Returning null instead of void means you would just get a NullPointerException the moment you use this value for anything. So you trade a compile time error for a runtime error which is way worse. Furthermore, you would have to define the return type as Object, which would be misleading and confusing. (And chaining would still not work.)

Status codes are usually used to indicate error conditions, but Java has exceptions for this purpose.

Returning this is not possible from static methods.

Returning a generic Success object would have no useful purpose.

JacquesB
  • 62.4k
  • 21
  • 137
  • 190