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

  • 3
    It will be grate to have some links to the discussion you have mentioned in the question, so that it will be useful for others and will help them understand the question more.
    – ManuPK
    Dec 1 '11 at 13:45
  • edited my question
    – Tarun
    Dec 1 '11 at 13:57

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.

  • 1
    The compiler would have to support this feature (so the calling code would compile) and it could save the object called and use it again without the calling method being altered. Dec 1 '11 at 14:34
  • Features to the OpenJDK of this nature are now handled as JDK Enhancement Proposals (JEPs) and indeed this is no longer listed (and I haven't seen it discussed in quite some time). Dec 1 '11 at 14:44

I don't believe this was ever formally proposed for the 2009 incarnation of Project COIN. This page purports to list all of the proposals, and I can't see one that corresponds.

If it wasn't proposed, it wouldn't have been considered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.