News for hackers. Stuff that matters.
Re:Java Feature Spotlight: Text Blocks by chhum on Friday May 01, 2020 @09:32AM (#23041798)
Interesting to see how Swift-inspired this feature is.
Re:Java Feature Spotlight: Text Blocks by pulse7 on Friday May 01, 2020 @09:34AM (#23041810)
Java has been inspired by many other languages... and continues to take good features and ideas from other languages...
Re:Java Feature Spotlight: Text Blocks by masklinn on Friday May 01, 2020 @09:49AM (#23041946)
It seems to be using a somewhat similar concept it calls "incidental white space", in order to limit the embedding of leading whitespace (unlike Python which just stores the entire triple-quoted string as-is), but is more permissive:

Text content can be indented less than the trailing delimiter, which I understand is an error in Swift

    String html = """
    ..............<html>
    ..............    <body>
    ..............        <p>Hello, world</p>
    ..............    </body>
    ..............</html>
    ..............    """;
The trailing delimiter can also be on the same line as the final content, which suppresses the final (new)line:

    """
    line 1
    line 2
    line 3"""
translates to

    "line 1\nline 2\nline 3"
whereas

    """
    line 1
    line 2
    line 3
    """
translates to

    "line 1\nline 2\nline 3\n"
I believe this requires escaping the newline in Swift instead (nb: according to the JEP this would also work in Java).
Re:Java Feature Spotlight: Text Blocks by _old_dude_ on Friday May 01, 2020 @10:19AM (#23042204)
Slash at the end of the line serve the same purpose in Java
Re:Java Feature Spotlight: Text Blocks by masklinn on Friday May 01, 2020 @03:41PM (#23045747)
> Slash at the end of the line serve the same purpose in Java

As I wrote in my comment, yes.

Re:Java Feature Spotlight: Text Blocks by imglorp on Friday May 01, 2020 @10:02AM (#23042056)
More likely from Kotlin. The only difference is % instead of $. They also grabbed Kotlin's data classes (records in java).

Lots of cross pollination.

Re:Java Feature Spotlight: Text Blocks by angus_gh on Friday May 01, 2020 @10:23AM (#23042247)
As the article says, they examined lots of languages, not just Kotlin (it would be arbitrary to confine their research to JVM languages..)

>> While Java could not adopt the Swift approach wholesale because of existing language constraints, the Java approach took as much inspiration from the good work that the Swift community did as we could -- and left room to take more in the future.

Re:Java Feature Spotlight: Text Blocks by therealdrag0 on Friday May 01, 2020 @10:11AM (#23042131)
Seen this in Scala too.