在普通的Java中,有许多种方法可以将整数转换为字符串,例如5变为"5"。这篇文章中的答案有几个很好的建议,String.valueOf(number)是我的最爱。
我的问题是Groovy是否提供其他/更好的方式来做到这一点?还是Java方法仍然是要走的路。
toString()对你有用吗?在我看来,它具有很强的描述性,并且在''+5性能方面胜过其他公司。
Integer x = 5;
System.out.println(x.toString());
Run Code Online (Sandbox Code Playgroud)
https://www.tutorialspoint.com/groovy/groovy_tostring.htm