Cava modifiers
Cava supports two categories of modifiers: the static modifier for defining class functions, and access modifiers (public, protected, private, final) for annotating class members.
| Modifier | Applies to | Has effect in Cava |
|---|---|---|
static | Class functions | Yes — used to define a class function |
public | Class members | No — class members are always publicly accessible |
protected | Class members | No — class members are always publicly accessible |
private | Class members | No — class members are always publicly accessible |
final | Class members | No — class members are always publicly accessible |
static
Use static to define class functions. Cava supports member variables but not class variables — applying static to a variable declaration causes a compilation error.
The following example shows a valid class function and an unsupported class variable declaration:
class Example {
static int i; // An error occurs during compilation.
static int main() {
return 0;
}
}The compilation error for the unsupported class variable:
ERROR cava.common.Diagnostics : benchmark/example.cava:1.15-2.16 [30001] static variable is not support:iFor more information on how static functions fit into the class model, see Classes and objects.
Access modifiers
Cava is syntactically compatible with the following access modifiers:
publicprotectedprivatefinal
Access modifiers do not affect access control in Cava. All class members are publicly accessible regardless of which modifier is applied. To avoid misleading anyone reading your code, do not use access modifiers in Cava.
The following example uses a public member variable. Despite the modifier, the variable is accessible in the same way as any other member:
class Example {
public double PI; // <==
Example() {
PI = 3.1415926;
}
static int main() {
Example example = new Example();
double a = example.PI;
return 0;
}
}