hi...here is the following Q
class D {
static {
boolean assertsEnabled = false;
assert assertsEnabled = true;
if (!assertsEnabled) {throw new RuntimeException();}
}
public static void main (
String[] args) {}
}
possible answers are as follows:
Which statements are true?
a. If assertions are not enabled at run time it prints an error message.
b. If assertions are not enabled at run time it prints nothing.
c. With assertions enabled it prints an error message.
d. With assertions enabled it prints nothing.
e. The assert statement is being used to check a class invariant--something that must be true about each instance of the class.
f. The assert statement is being used to prevent the class from being initialized if assertions are disabled.
g. The assert statement is being used to check a postcondition--something that must be true when the method completes successfully.
h. A compiler error is generated.
i. None of the above.
the answer is a,d,f. I don't have a problem with that.
i just wonder what the compiler thinks of assert being there, if assertions are disabled - does it not stress out about the syntax?