If "obj = null" then "obj instanceof String" returns false (never an exception)Commit: a213b3c8 - eprog instance of gotchas
Author: obrhubr <obrhubr@gmail.com>
Date: 2026-01-12T18:36:51+01:00
Changes: 12 note(s) changed (12 added, 0 modified, 0 deleted)
Ap->IRX#;C
Note did not exist
If "obj = null" then "obj instanceof String" returns false (never an exception)If "obj = null" then "obj instanceof String" returns false (never an exception)| Field | Before | After |
|---|---|---|
| Text | <div><code><span style="font-family: "Liberation Sans";">If "</span>obj = null"</code> then "<code>obj instanceof String"</code> returns {{c1::false (never an exception)}}</div> |
D3~R~/O`**
Note did not exist
instanceof tests whether an instance has a same dynamic type or if it implements an interface.instanceof tests whether an instance has a same dynamic type or if it implements an interface.| Field | Before | After |
|---|---|---|
| Text | <div><code>instanceof</code> tests whether {{c1::an instance has a same <b>dynamic type</b>}} or {{c1::if it implements an <b>interface</b>}}.</div> |
G#$#7KW!b}
Note did not exist
instanceof never throws an exception, just compile errors.| Field | Before | After |
|---|---|---|
| Front | Instance of can result in a Compile / Runtime / No error? | |
| Back | <div><code>instanceof</code> never throws an exception, just <b>compile</b> errors.</div> |
I0s;#,Wh%?
Note did not exist


| Field | Before | After |
|---|---|---|
| Front | <img src="paste-f485e58a003acd0f29903efd63e9440b14068a5c.jpg"><br>Compile/Runtime/No Error | |
| Back | No error, valid for loop. |
IKMb!{98`
Note did not exist


| Field | Before | After |
|---|---|---|
| Front | <img src="paste-e33a7d35e8694abacbdbd499304129858fb8fe03.jpg"><br>Compile/Runtime/No Error? | |
| Back | Valid for loop. |
LHfofYY0cF
Note did not exist
| Field | Before | After |
|---|---|---|
| Front | Can we ust <b>++</b> and <b>--</b> on floats and doubles? | |
| Back | Yes, that is allowed and increments by 1.0. |
MpWDjk%Tfz
Note did not exist
| Field | Before | After |
|---|---|---|
| Text | Instance of returns true if:<br><ul><li>{{c1::Implements the interface}}</li><li>{{c2::Is of the same dynamic type}}</li><li>{{c3::Is a subtype of the dynamic type}}</li></ul> |
bxDOHVL#p]
Note did not exist
t instanceof List<String will not compile as it cannot check the parametrised type Animal -> Dog and Animal -> Cat. animal instanceof Dog/Cat allowed, but dog = new Dog(); dog instanceof Cat throws compile error.final classes (that don't implement that interface).Animal a = getanimal() could get a Dog which implement List thus a instanceof List is not a compile error. t instanceof List<String will not compile as it cannot check the parametrised type Animal -> Dog and Animal -> Cat. animal instanceof Dog/Cat allowed, but dog = new Dog(); dog instanceof Cat throws compile error.final classes (that don't implement that interface).Animal a = getanimal() could get a Dog which implement List thus a instanceof List is not a compile error.| Field | Before | After |
|---|---|---|
| Text | A compile error can result from an <b>instance of </b>check if:<br><ul><li>{{c1::<i><b>Primitive</b></i> types cannot be used with Instance Of}}</li><li>{{c2::Cannot check for <b><em>generics</em></b>, type erasure prevents this.<br><code> t instanceof List<String</code> will not compile as it cannot check the parametrised type}}</li><li>{{c3::Comparing <i><b>siblings</b></i>:<br><div><code> Animal -> Dog</code> and <code>Animal -> Cat</code>. <br> Check for <code>animal instanceof Dog/Cat</code> allowed, but <code>dog = new Dog(); dog instanceof Cat</code> throws compile error.}}</div></li><li><div>{{c4::Interface checks for <i><code>final</code> classes</i> (that don't implement that interface).<br> A final class cannot implement an interface in a subclass, thus error<br> <code>Animal a = getanimal()</code> could get a <code>Dog</code> which <br> might <code>implement List</code> thus <code>a instanceof List</code> is not a compile error.}}</div></li></ul> |
fJL&tF*QW&
Note did not exist


| Field | Before | After |
|---|---|---|
| Front | <img src="paste-e0cbcc8d646d0785d63ce579c103d7fcfead5a58.jpg"><br>Compile/Runtime/no Error | |
| Back | No error, valid for loop |
i2g|!nNV|m
Note did not exist
| Field | Before | After |
|---|---|---|
| Text | We can omit everything but {{c1::the semicolons}} in the for loop <b>for(...)</b> |
osPOmm:i4.
Note did not exist


| Field | Before | After |
|---|---|---|
| Front | <img src="paste-6451454cfb845d5c319df053e0bf4d13f446b8b5.jpg"><br>Compile/Runtime/No Error | |
| Back | No error, valid for loop. |
pycoxP)lJk
Note did not exist
| Field | Before | After |
|---|---|---|
| Front | <b>10 / -2</b> in Java gives the result <b>5 </b>or <b>-5</b>? | |
| Back | <b>-5</b> as integer division also supports negatives. |