Interpolating Strings Like a King in Java 21 - Inside Java Newscast #47

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น •

  • @DinMamma002
    @DinMamma002 ปีที่แล้ว +10

    While late, it's looks more awesome than other languages string interpolation feature!

  • @prdoyle
    @prdoyle ปีที่แล้ว +6

    Wow, what a dense video. I had to keep pausing and replaying parts so I could absorb all the info!

    • @MiguelPerez-hn8bg
      @MiguelPerez-hn8bg ปีที่แล้ว +1

      I even had to put it in 0.75x some times 😆

  • @MiguelPerez-hn8bg
    @MiguelPerez-hn8bg ปีที่แล้ว +9

    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 🙇

    • @ricardojlrufino
      @ricardojlrufino ปีที่แล้ว

      Exactly what I had thought. It's time for JSON to become a native part of Java

    • @ChrisB_Crisps
      @ChrisB_Crisps ปีที่แล้ว

      Groovy allows to return JSON or XML objects for more a decade. Asique a ver si miramos chatungo. I hope that helps

  • @aazzrwadrf
    @aazzrwadrf ปีที่แล้ว +2

    very well thought out implementation.

  • @onebeartoe
    @onebeartoe ปีที่แล้ว +1

    Happy King's Day!

  • @cpunktspunkt748
    @cpunktspunkt748 ปีที่แล้ว

    well explained thanks...when I remember how easy and clean this looks in scala, I get sad

  • @prashantmeena6137
    @prashantmeena6137 ปีที่แล้ว +3

    This is so cool

  • @devtoro5601
    @devtoro5601 ปีที่แล้ว +1

    GREAT!

  • @alexpishvanov736
    @alexpishvanov736 ปีที่แล้ว +8

    As usual, only one Java feature description sounds like whole simpler programming language tutorial )))

  • @pguti778
    @pguti778 ปีที่แล้ว

    What about SQL??

  • @PietervandenHombergh
    @PietervandenHombergh ปีที่แล้ว +3

    Nice to rimind us of our Kings day.

  • @kanizh
    @kanizh ปีที่แล้ว

    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.

  • @ylioo
    @ylioo ปีที่แล้ว +1

    So we have to wait for 2.5 years from today to have this feature in an LTS version?

    • @prdoyle
      @prdoyle ปีที่แล้ว +1

      It will be in 21 as a preview feature.

    •  ปีที่แล้ว +1

      In short: yes. But what do you expect? I'm glad they want community feedback for such features.

    • @ylioo
      @ylioo ปีที่แล้ว +2

      @ 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).

  • @Jankoekepannekoek
    @Jankoekepannekoek ปีที่แล้ว +5

    What, is dutch King's Day such a big deal that it deserves a mention by the Java youtube channel? I'm surprised.

  • @LemubitAcademy
    @LemubitAcademy ปีที่แล้ว +2

    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!

    • @nipafx
      @nipafx ปีที่แล้ว +2

      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.

    • @prdoyle
      @prdoyle ปีที่แล้ว +2

      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.

    • @LemubitAcademy
      @LemubitAcademy ปีที่แล้ว

      @@nipafx Oh, I now see the reason behind that, makes sense!

    • @LemubitAcademy
      @LemubitAcademy ปีที่แล้ว

      @@prdoyle Yeah, makes sense

  • @kamurashev
    @kamurashev 9 หลายเดือนก่อน

    I hate that backslash so bad I want to throw my phone through the window

  • @fabianmerki4222
    @fabianmerki4222 ปีที่แล้ว +3

    why \ ...? just to be different? JS and many others are using ${...}

    • @jasonbullers
      @jasonbullers ปีที่แล้ว +2

      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.

    • @jonas9
      @jonas9 ปีที่แล้ว

      why $...? just to be different? C# and many others are using {...}.