Processing, static
用法介紹。
說明
用於將變量定義為"class variable" 並將方法定義為“類方法”的關鍵字。當使用static
關鍵字聲明變量時,該類的所有實例共享同一個變量。當使用static
關鍵字定義類時,無需創建類的實例即可使用其方法。上麵的示例演示了這些用途中的每一個。
此關鍵字是 Java 編程的重要組成部分,通常不與 Processing 一起使用。有關更多信息,請參閱 Java 語言參考或教程。
例子
void setup() {
MiniClass mc1 = new MiniClass();
MiniClass mc2 = new MiniClass();
println( mc1.y ); // Prints "10" to the console
MiniClass.y += 10; // The 'y' variable is shared by 'mc1' and 'mc2'
println( mc1.y ); // Prints "20" to the console
println( mc2.y ); // Prints "20" to the console
}
static class MiniClass {
static int y = 10; // Class variable
}
void setup() {
println(MiniClass.add(3, 4)); // Prints "7" to the console
}
static class MiniClass {
static int add(int x, int y) {
return(x + y);
}
}
相關用法
- Processing strokeJoin()用法及代碼示例
- Processing str()用法及代碼示例
- Processing strokeWeight()用法及代碼示例
- Processing stroke()用法及代碼示例
- Processing strokeCap()用法及代碼示例
- Processing scale()用法及代碼示例
- Processing splice()用法及代碼示例
- Processing super用法及代碼示例
- Processing subset()用法及代碼示例
- Processing saveJSONArray()用法及代碼示例
- Processing saveXML()用法及代碼示例
- Processing switch用法及代碼示例
- Processing sqrt()用法及代碼示例
- Processing serverEvent()用法及代碼示例
- Processing save()用法及代碼示例
- Processing saveStrings()用法及代碼示例
- Processing saveTable()用法及代碼示例
- Processing shorten()用法及代碼示例
- Processing saturation()用法及代碼示例
- Processing settings()用法及代碼示例
- Processing spotLight()用法及代碼示例
- Processing setLocation()用法及代碼示例
- Processing splitTokens()用法及代碼示例
- Processing setResizable()用法及代碼示例
- Processing specular()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 static。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。