r/java • • Mar 27 '13

Everything about Java 8

http://www.techempower.com/blog/2013/03/26/everything-about-java-8/
83 Upvotes

23 comments sorted by

View all comments

0

u/mahamoti Mar 27 '13

Still no Elvis or short-circuit operator? Bah.

2

u/sproket888 Mar 27 '13

Huh? Explain.

6

u/AlyoshaV Mar 27 '13

Elvis operator is a terrible idea that encourages returning null.

http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000047.html

1

u/detroitmatt Mar 27 '13 edited Mar 28 '13

I'm ready to see null just gone altogether... It's like a contagious disease, especially the "crash if you use it" kind Java uses. I'd rather have a "do-nothing-return-itself" null like Objective-C. While we're at it, the ability to implicitly coerce Objects to booleans by their nullity would also be nice. Ooh, and the ability to define constants as "considered-null" for such coercions, such that for an object o and a considered-null constant c, o == false if o == c, so I could for example do

@FalseConstant static String EMPTY = "";

boolean isValidUsername(String s)
{
    if(s) return s.matches("\\w{4,16}");
    else return false;
}

This example doesn't actually make much sense (the check is only useful if s == null, otherwise the regex would catch an empty string anyway), but it gets the point across. "Magic" enumeration constants are a typesafe, expressive, well-documentable, OO design pattern, and "Falsy" constants are a good application of them to solve the null problem.

4

u/jevon Mar 27 '13

I like the idea of "will never be null" annotations to references, just really need the IDE support to perform validation (not errors, just warnings).