Expressions
Expressions are made up of variables, operators, and method invocations.
Intervals
Intervals are specific to the ARL rule language.
Intervals can be used in swicth expressions, and with the in
and !in operators.
Intervals can be finite or infinite, using -oo for minus infinity and
+oo for plus infinity. Interval bounds can be included in intervals.
For example:
2 in [1,3]
x !in ]-oo,0]
switch
The switch keyword can be used in expressions. It is quite similar to the
switch expression introduced in Java 14.
String label =switch (experience) {
case1, 2:"Junior";
case3, 4:"Senior";
case5:"Expert";
default:thrownewIllegalArgumentException("unexpected experience");
};
-> is used as a separator in Java 14, : is used as a
separator in the ARL rule language.For more information about the types that can be used with switch, see the Statements section.
Instance creation
Like in Java, the new keyword can be used to create an instance, with or without
passing parameter values.
List mylist = newArrayList();
Point myPoint = newPoint(1,2);
Method invocation
Like in Java, static methods and instance methods can be invoked in the ARL rule language.
The following example shows a static method call:
BigInteger bi = ...
if (BigInteger.valueOf(12).equals(bi))
// code to be executed
The following example shows an instance method call:
String s = ...
if (s.contains("A"))
// code block
Some methods can take a variable number of arguments. This is also known as Variable Arguments, or Varargs.
The following example shows a method with a variable number of arguments:
public static int sum(int... args) {
int sum = 0;
for(int x: args){
sum += x;
}
return sum;
It can be used as follows:
int result = sum(2,5,6);
void return type can only be used as
statements.