该示例来自一门课程,用于比较 java 中的两个对象:
public class Complex {
...
public boolean equals (Object obj) {
if (obj instanceof Complex) { // if obj is "Complex" (complex number)
Complex c = (Complex) obj // No idea
return (real == c.real) && (imag == c.imag);
// I'm guessing real means [this].real
}
return false;
}
}
所以,我的问题是:“这是什么意思:Complex c = (Complex) obj
实际上是什么意思”?
我也使用过 python 和 c++,java 对我来说是新的。