【问题】
想要在Java中输入多行代码,尝试了使用:
1 2 3 4 | String multiLineComments = " /* \ * this is \ * multi line comment \ */ "; |
结果不行。
【解决过程】
1.最后参考了这个:
Java – string declaration occupying multiple lines? [closed]
去试了试:
1 2 3 4 | String multiLineComments = "/* " + "* this is " + "* multi line comment " + "*/" ; |
以为就可以了。后来经过实际测试,发现坑爹啊,根本还是单行字符串。
2.最后改为,很挫的,自己添加换行:
1 2 3 4 | String multiLineComments = "/* \n" + "* this is \n" + "* multi line comment \n" + "*/" ; |
才是真正的实现多行字符串的。
【总结】
Java中的多行字符串,竟然不直接支持。很是诧异。也觉得很是诡异。
转载请注明:在路上 » 【已解决】Java中输入多行字符