Yield considered harmful

Mark Thornton mthornton at optrak.co.uk
Fri Jul 9 14:44:23 PDT 2010

Alex Blewitt wrote:
> As has been noted elsewhere, the inconsistency between 'this' as a reference to the SAM instance and 'yield' as a way of return-from-lambda is not a good development. Given that 'this' is already defiend, why not use 'return' as well? Almost all Java developers will understand this immediately; and it doesn't prevent the kind of macro use that has been described about elsewhere in the future. 
> Furthermore, 'yield' already has an existant meaning in Java:
> http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/api/java/lang/Thread.html#yield()
> "Causes the currently executing thread object to temporarily pause and allow other threads to execute."
> Having a keyword mean something completely different from a well defined term in multi-threading (and one that's been there since Java 1.0 days) seems folly at best. 
On the other hand Thread.yield() is so rarely used that very few Java 
programmers are likely to be bothered by the additional meaning. I 
wonder how many people have used it to any practical effect in the last 
five years.
That said, I'm also not keen on the proposed use of yield.

Mark Thornton

More information about the lambda-dev mailing list