<code>if (obj instanceof B) { B b = (B) obj; b.someBMethod(); } </code></pre>
- Acheck_circle
Idiomatic safe downcast pattern
- B
Compile error
- C
Cannot use instanceof
- D
Always crashes
Explanation
Standard guarded downcast.
AP Computer Science A· difficulty 4/5
<code>if (obj instanceof B) { B b = (B) obj; b.someBMethod(); } </code></pre>
Idiomatic safe downcast pattern
Compile error
Cannot use instanceof
Always crashes
Explanation
Standard guarded downcast.
Want 10 more like this — adaptive to your weak spots?