Java Reference
In-Depth Information
A block expression is a list of statements that may include variable declarations
or other expressions within curly braces. If the last statement is an expression,
the value of a block expression is the value of that last expression; otherwise, the
block expression does not represent a value. Listing 3.6 shows two block expres-
sions. The first expression evaluates to a number represented by the
subtotal
value. The second block expression does not evaluate to any value as the last
expression is a
println()
function that is declared as a
Void
.
Listing 3.6
Block Expressions
// block expression with a value
var total = {
var subtotal = 0;
var ndx = 0;
while(ndx < 100) {
subtotal += ndx;
ndx++;
};
subtotal; // last expression
};
//block expression without a value
{
var total = 0;
var ndx = 0;
while(ndx < 100) {
total += ndx;
ndx++;
};
println("Total is {total}");
}
The
throw
statement is the same as Java and can only throw a class that extends
java.lang.Throwable
.
The
try
/
catch
/
finally
expression is the same as Java, but uses the JavaFX syntax:
try {
} catch (e:SomeException) {
} finally {
}
Search WWH ::
Custom Search