我讀過OOP中的很多大型項目,我注意到其中很多人使用this.[variable]
,[ClassName].[staticVariable]
。例如:使用「this」的好處。
public class ABC {
private float mX;
public static float y;
public float getX() {
return this.mX;
}
public float doSomethingWithY() {
return ABC.y;
}
}
即使使用Eclipse自動生成Getters & Setters
功能,還配備了this.[variable]
,雖然這是不必要的,因爲沒有本地變量聲明那裏。
使用這些符號有什麼優點,或者它只是一種代碼風格?
編輯所以有些人不會誤解。我知道this
和[ClassName].[staticVariable]
代表什麼。但在這種情況下,這是不必要的。問題是:即使沒有必要,爲什麼古魯編碼器仍然會添加它?當他們需要更新/修復一個龐大的項目時,是否會有優勢和劣勢?
它的編碼風格......通過了StyleCop使用,默認情況下不被resharper使用。 – Tanmoy 2012-02-07 05:56:02