Skip to main content
added 478 characters in body
Source Link
JacquesB
  • 62.3k
  • 21
  • 136
  • 190

Status codes are usually used to indicate error conditionsSome methods, like System.out.println does not return anything useful, but Java has exceptionsis called purely for this purposeside effect.

Returning thisvoid is not possible from static methodsa 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 requirejust 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(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.

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 null instead of void would require you to define the return type as Object would be misleading and confusing. And chaining would still not work.

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.

Source Link
JacquesB
  • 62.3k
  • 21
  • 136
  • 190

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 null instead of void would require you to define the return type as Object would be misleading and confusing. And chaining would still not work.