gpt4 book ai didi

java - String + 运算符是如何实现的?

转载 作者:行者123 更新时间:2023-12-01 12:52:40 25 4
gpt4 key购买 nike

执行时会发生什么

String s = "str" + 2;

有没有String的方法与 + 完全对应的类运算符?

最佳答案

来自Java Language Specification (强调我的):

If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run time. The result of string concatenation is a reference to a String object that is the concatenation of the two operand strings.

关于java - String + 运算符是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24105989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com