Decisions Flashcards
Where can labels be used?
On loops, switches, if statements
Pattern matching variable can also be?
Reassigned into something else inside flow scope
Pattern matching variable can also be?
Final
What happens if you instanceof check int primitive with Integer?
Casting exception
What happens if you instanceof check local variable with same type via pattern matching?
Compile error where variable is already defined
What happens if you instanceof check local variable with same supertype via pattern matching?
Compile error that pattern matching variable is supertype of local variable
What happens if you instanceof check local variable with same subtype via pattern matching?
It compiles and you have pattern matching variable
What is flow scoping?
You can define pattern matching variable while evaluating with instanceof. That variable is only available inside that check statement scope. If you negate instanceof expression, then that variable is available to all other evaluations (if-else if), but not outside evaluations scope
What primitives cannot be used in switch statement?
boolean, long, float and double
Can switch statement be empty?
Yes
Do switch statements support “break”?
Yes
Can cases inside switch expression be listed in same line?
Yes
Do switch expressions support “break”?
No
What are rules regarding ; in switch expressions?
They must appear outside expression and they must appear at the end of each case, instead of block {}. There they must appear inside code block.
How does switch expression look like?
- It contains a type, identifier and a switch statement, but cases are comprised of arrows ->, not :. -
- They must contain ; at the end, and at the end of each case, with exception of code blocks {}.