相比较于使用不同变量名,this关键字调用是否会产生更大的运行时开销?
来源:2-4 this关键字
慕斯9562566
2022-11-14 18:13:25
相比较于使用不同变量名,this关键字调用是否会产生更大的运行时开销?
public class Test {
int anInt;
float aFloat;
double aDouble;
Test(int anInt, float aFloat,double aDouble) {
this.aDouble = aDouble;
this.aFloat = aFloat;
this.anInt = anInt;
}
}public class Test {
int anInt;
float aFloat;
double aDouble;
Test(int _anInt, float _aFloat, double _aDouble) {
aDouble = _aDouble;
aFloat = _aFloat;
anInt = _anInt;
}
}这两种写法会有运行时开销差异码?如果有,开销有多大?
1回答
同学你好,没有差异,方法中访问成员变量时,成员变量前默认也是有this的。
祝学习愉快~
相似问题