= Java中的运算符 [英] = operator in java
问题描述
有人可以向我解释为什么可以这样做:
can somebody explain me why it's possible to do:
String s = "foo";
在没有操作符重载的情况下(在这种情况下为"=)
how is this possible without operator overloading (in that case the "=")
我来自C ++背景,这可以说明...
I'm from a C++ background so that explains...
推荐答案
在这种情况下,没有重载.与C ++不同的Java片段是"的定义-Java编译器将"中的任何内容转换为java.lang.string,因此在您的示例中也是一个简单的赋值.在C ++中,编译器将"转换为char const *,因此需要从char const *转换为std :: string.
In this case there is no overloading. The java piece that differs from C++ is the definition of "" - The java compiler converts anything in "" into a java.lang.string and so is a simple assignment in your example. In C++ the compiler converts "" into a char const * and so needs to have a conversion from char const* to std::string.
这篇关于= Java中的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!