Java multiline string

前端 未结 30 3033
醉梦人生
醉梦人生 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:19

    Actually, the following is the cleanest implementation I have seen so far. It uses an annotation to convert a comment into a string variable...

    /**
      
        
        
          

    Hello
    Multiline
    World

    */ @Multiline private static String html;

    So, the end result is that the variable html contains the multiline string. No quotes, no pluses, no commas, just pure string.

    This solution is available at the following URL... http://www.adrianwalker.org/2011/12/java-multiline-string.html

    Hope that helps!

提交回复
热议问题