Java Void Methods – Implicitly Returning This

java

there are a couple of discussion on SO about setter methods returning "this" type. And looks like java 7 had the proposal of void methods returning this.
But this proposal could not make it to java 7 features.
I could not find if this proposal is moved on to java 8 or future or have been completely discarded. Is it?

Ref link – https://stackoverflow.com/questions/31584/design-java-and-returning-self-reference-in-setter-methods

Best Answer

I can't seem to find any sources of that, but I believe this feature was dropped completely. There are numerous reasons I can think of:

  • performance - each void method now has an extra return opcode and every place where this method is called needs implicit pop unless it actually uses method chaining

  • backward compatibility - compiling against this feature suddenly makes the code backward incompatible because the contract of every void method has changed

Of course this can also be implemented by the compiler (calling method on void? You probably meant this, let me add this implicitly), don't know what are the disadvantages of this approach.