JEP 302: Lambda Leftovers

Nicolai Parlog nipa at codefx.org
Wed Dec 7 10:30:56 UTC 2016


 Hi!

Great proposal! Especially the underscore is cool, much better than
naming those variables "ignored". I wonder whether I should start using
two underscores now so I can later replace them with a single one. :) I
guess it will be possible to use "_" for multiple parameters?

I would like to request a feature regarding method references. I like
making non-public methods static to convey the fact that they do not
interact with or even change the state of the object they are called on.
But this conflicts with the ease of method references:

	// `isGenderNeutralName` is an instance method
	names.filter(this::isGenderNeutralName)

vs

	// `isGenderNeutralName` is a static method
	names.filter(GenderNeutralNameProcessor::isGenderNeutralName)

As a consequence I often go back and make it an instance method to keep
the reference readable but it hurts because I give up on an immutability
signal.

It would be awesome if it were possible to reference a static method in
the same class without repeating the entire class name. Reusing the
`class` keyword seems like an obvious* choice:

	// `isGenderNeutralName` is a static method
	names.filter(class::isGenderNeutralName)

Using Martijn's shorthand, IANALE (I Am Not A Language Expert) so I have
no idea whether this is tractable but it would surely be a nice addition.

 so long ... Nicolai


* I am aware that the obvious idea might be also be a terrible idea.



On 07.12.2016 00:50, mark.reinhold at oracle.com wrote:
> New JEP Candidate: http://openjdk.java.net/jeps/302
> 
> - Mark
> 

-- 

PGP Key:
    http://keys.gnupg.net/pks/lookup?op=vindex&search=0xCA3BAD2E9CCCD509

Web:
    http://codefx.org
        a blog about software development
    https://www.sitepoint.com/java
        high-quality Java/JVM content
    http://do-foss.de
        Free and Open Source Software for the City of Dortmund

Twitter:
    https://twitter.com/nipafx


More information about the platform-jep-discuss mailing list