【发布时间】:2013-11-04 13:13:21
【问题描述】:
我对@987654321@ 声明有疑问。 假设我在这里有这段代码(非常愚蠢和无用,但传达了信息):
class Calculate{
int x,y;
final int g = 5;
//Constructor
public Calculate(int a, int b) {
x = a; y = b;
}
public int sumAddG() {
return (x+y+g);
}
//comparing method
public boolean same(Calculate in) {
if(this.sumAddG() == in.sumAddG()) { // <-- This is what I am curious about
return true;
} else {
return false;
}
}
那么我的代码对吗?当我使用this.SumAddG() 时 - 我是指使用 this 类实例的 instance variables 方法 SumAddG() 的结果吗?
【问题讨论】:
-
您不能在静态上下文中使用
this关键字。这会产生编译错误。 -
好的,去掉静态的^^现在?
-
只有一个参数的静态比较方法没有多大意义...
-
啊啊啊啊! >.
-
我还将
same更改为以下内容:public boolean same (Calculate in) { return this.sumAddG() == in.sumAddG(); }