News for hackers. Stuff that matters.
Re:Raw String Literals Removed From Java 12 as Feature Set F... by mabbo on Saturday December 22, 2018 @10:18AM (#18740887)
JEP325 seems like a nice little improvement. Just a linguistic trick but still lovely.

   int numLetters = switch (day) {
       case MONDAY, FRIDAY, SUNDAY -> 6;
       case TUESDAY                -> 7;
       case THURSDAY, SATURDAY     -> 8;
       case WEDNESDAY              -> 9;
   };
Switches can return values, and can have multiple cases on the same line.

I'm sure in 2 years when my organization gets around to switching to Java 12, I'll enjoy using it.

Re:Raw String Literals Removed From Java 12 as Feature Set F... by helfire on Saturday December 22, 2018 @10:35AM (#18740957)
Java 12 is not a long term support release and will only be supported until September 2019 (so don't switch to it in 2 years :).

Interesting to see the faster pace releases to get feedback on features, but many major libraries are just getting Java 11 support.

Re:Raw String Literals Removed From Java 12 as Feature Set F... by cogman10 on Saturday December 22, 2018 @02:39PM (#18742085)
This is mostly due to Java 9 breaking everything.

Post Java 11, I doubt you will see the same problems you did with going from 8 to 9 or 11

Re:Raw String Literals Removed From Java 12 as Feature Set F... by aardvark179 on Saturday December 22, 2018 @06:13PM (#18743036)
It’s only a preview feature in 12, so you need to give a command line switch to java for it to be enabled.

It’s also the first part of a much larger feature adding pattern matching to the Java language. Getting all the ducks in a row for this sort of thing is tricky because it touches so many other ares, but switch expressions can be delivered on their own quite nicely.

Adding patterns means looking at variable scopes (where is a variable bound in a pattern in scope?), record classes (because destructuring patterns should not be implemented by hand everywhere), and even constants and raw string literals (because being able to switch on regexps would be nice, and you need a good way to write that).

Re:Raw String Literals Removed From Java 12 as Feature Set F... by mabbo on Saturday December 22, 2018 @08:06PM (#18743665)
That sounds lovely. Fully functional pattern matching in Java would be a godsend.
Re:Raw String Literals Removed From Java 12 as Feature Set F... by maxxxxx on Saturday December 22, 2018 @11:30AM (#18741197)
What happens if the value is not found? I would love it if you could throw an exception from a default block.
Re:Raw String Literals Removed From Java 12 as Feature Set F... by hocuspocus on Saturday December 22, 2018 @12:54PM (#18741625)
You need a default clause when your cases aren't exhaustive otherwise. The compiler will insert a default clause transparently if you switch over an enum: https://openjdk.java.net/jeps/325

The cases of a switch expression must be exhaustive; for any possible value there must be a matching switch label. In practice this normally means simply that a default clause is required; however, in the case of an enum switch expression that covers all known cases (and eventually, switch expressions over sealed types), a default clause can be inserted by the compiler that indicates that the enum definition has changed between compile-time and runtime. (This is what developers do by hand today, but having the compiler insert it is both less intrusive and likely to have a more descriptive error message than the ones written by hand.)

This is pretty much the behavior you'd expect if you're familiar with languages that support pattern-matching.

Re:Raw String Literals Removed From Java 12 as Feature Set F... by wbl on Saturday December 22, 2018 @02:47PM (#18742115)
Introduced for the first time in Algo 68 as far as I know.