为什么在Scala中没有字符串插值? [英] Why is there no string interpolation in Scala?

查看:71
本文介绍了为什么在Scala中没有字符串插值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不只是一个闲聊,我想知道是否有人知道Scala不支持类似于Groovy和其他语法上更好的Java"的插值的实际设计原因吗?

例如

var str1 = "World";
var str2 = "Hello, ${str1}";

解决方案

建议的解决方案是在使用+时省略空格.

"a="+a+", b="+b

它已经

e.g.

var str1 = "World";
var str2 = "Hello, ${str1}";

The proposed solution is to omit spaces when using +.

"a="+a+", b="+b

It has been suggested that a Swiss keyboard layout makes this very natural to type, so the creators of Scala don't feel enough pain to justify complicating the langauge in this direction :)

这篇关于为什么在Scala中没有字符串插值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆