static
The static modifier defines class functions. Apply it to methods only — Cava does not support class variables. For more information, see Classes and objects.
Correct usage — static method:
class Example {
static int main() {
return 0;
}
}Incorrect usage — static variable:
Applying static to a variable causes a compilation error:
class Example {
static int i; // Error: static variables are not supported.
static int main() {
return 0;
}
}ERROR cava.common.Diagnostics : benchmark/example.cava:1.15-2.16 [30001] static variable is not support:iAccess modifiers
Cava is syntactically compatible with these access modifiers:
publicprotectedprivatefinal
However, these modifiers do not affect the access to a class member. No matter which access modifier you use, all class members are publicly accessible regardless of which modifier you apply:
class Example {
public double PI; // <==
Example() {
PI = 3.1415926;
}
static int main() {
Example example = new Example();
double a = example.PI;
return 0;
}
}Because access modifiers have no effect in Cava, avoid using them to prevent confusion.
该文章对您有帮助吗?