Very promising feature and it's just a preview! I like the flexibility of having template processors that can return not only strings like most other languages but also arbitrary objects like JSONObject. Kudoz to you Oracle people 🙇
A very primitive implementation... The JSON example looks as a cripple. Usually you don't want to throw exceptions for injection, but escape characters to produce valid json from any values. And doing so makes code quite cumbersome and inefficient - first, quote strings, then concat everything, then parse it again. Also `List` loses all the compile-time information. The `InterpolatedStringHandler` from C# looks more flexible and mature, allows to cover many more scenarios.
@ to have string interpolation in Java, before the first humans step foot on Mars.
ปีที่แล้ว +2
Well, we will now have much more than that ;) I have come to peace with the fact, that Java isn't the first language to add random features but waits for what works how well in practice. There's still Scala, Groovy or Kotlin if more edgy features are needed on the JVM. The upside is that Java doesn't have too many awful decisions which now weigh everything down. There still are some, of course, and I'd really like to have limited operator overloading for numeric classes (BigInteger, BigDecimal, Complex, Vector (the mathematical one and the new SIMD stuff).
I get your point. Others have asked for replacing \ with $. But either way, then a template string would be indistinguishable from a "regular" string (at the moment \{ is illegal in strings), which would complicate matters elsewhere, e.g. you couldn't enforce that a template string needs a processor.
This helps it catch certain kinds of errors. The sequence "\{" is currently not valid in Java strings, so it couldn't be confused for anything else. If you write "\{" into a string thinking it will be templated, but aren't using a template processor, you'll get an error.
Backwards compatibility. Since template strings are strings and ${} could already legally appear in strings, they'd have either broken people or had to introduce some new, special type of string for use here instead of just supporting text blocks. \{ is not a valid escape character right now, so using it won't break anyone.
While late, it's looks more awesome than other languages string interpolation feature!
Wow, what a dense video. I had to keep pausing and replaying parts so I could absorb all the info!
I even had to put it in 0.75x some times 😆
Very promising feature and it's just a preview! I like the flexibility of having template processors that can return not only strings like most other languages but also arbitrary objects like JSONObject. Kudoz to you Oracle people 🙇
Exactly what I had thought. It's time for JSON to become a native part of Java
Groovy allows to return JSON or XML objects for more a decade. Asique a ver si miramos chatungo. I hope that helps
very well thought out implementation.
Happy King's Day!
well explained thanks...when I remember how easy and clean this looks in scala, I get sad
This is so cool
GREAT!
As usual, only one Java feature description sounds like whole simpler programming language tutorial )))
What about SQL??
Nice to rimind us of our Kings day.
A very primitive implementation... The JSON example looks as a cripple. Usually you don't want to throw exceptions for injection, but escape characters to produce valid json from any values. And doing so makes code quite cumbersome and inefficient - first, quote strings, then concat everything, then parse it again. Also `List` loses all the compile-time information. The `InterpolatedStringHandler` from C# looks more flexible and mature, allows to cover many more scenarios.
So we have to wait for 2.5 years from today to have this feature in an LTS version?
It will be in 21 as a preview feature.
In short: yes. But what do you expect? I'm glad they want community feedback for such features.
@ to have string interpolation in Java, before the first humans step foot on Mars.
Well, we will now have much more than that ;) I have come to peace with the fact, that Java isn't the first language to add random features but waits for what works how well in practice. There's still Scala, Groovy or Kotlin if more edgy features are needed on the JVM. The upside is that Java doesn't have too many awful decisions which now weigh everything down. There still are some, of course, and I'd really like to have limited operator overloading for numeric classes (BigInteger, BigDecimal, Complex, Vector (the mathematical one and the new SIMD stuff).
What, is dutch King's Day such a big deal that it deserves a mention by the Java youtube channel? I'm surprised.
I'm assuming she's dutch lol
Love this new addition :) ...would have liked if we didn't have to include that backslash before the braces though, but this is a great start!
I get your point. Others have asked for replacing \ with $. But either way, then a template string would be indistinguishable from a "regular" string (at the moment \{ is illegal in strings), which would complicate matters elsewhere, e.g. you couldn't enforce that a template string needs a processor.
This helps it catch certain kinds of errors. The sequence "\{" is currently not valid in Java strings, so it couldn't be confused for anything else. If you write "\{" into a string thinking it will be templated, but aren't using a template processor, you'll get an error.
@@nipafx Oh, I now see the reason behind that, makes sense!
@@prdoyle Yeah, makes sense
I hate that backslash so bad I want to throw my phone through the window
why \ ...? just to be different? JS and many others are using ${...}
Backwards compatibility. Since template strings are strings and ${} could already legally appear in strings, they'd have either broken people or had to introduce some new, special type of string for use here instead of just supporting text blocks. \{ is not a valid escape character right now, so using it won't break anyone.
why $...? just to be different? C# and many others are using {...}.