Java multiline string

前端 未结 30 2967
醉梦人生
醉梦人生 2020-11-22 15:55

Coming from Perl, I sure am missing the \"here-document\" means of creating a multi-line string in source code:

$string = <<\"EOF\"  # create a three-l         


        
30条回答
  •  一向
    一向 (楼主)
    2020-11-22 16:42

    JEP 355: Text Blocks (Preview) aims to cover this functionality, it is currently targeting JDK 13 as a preview feature. Allowing to write something like:

    String s = """
        text
        text
        text
      """;
    

    Previous to this JEP, in JDK12, JEP 326: Raw String Literals aimed to implement a similar feature, but it was finally withdrawn.

提交回复
热议问题