I've just joined - currently studying for my OCJA - in three weeks time. Over the last week I've done the first two Enthuware mock exams - 70% and 71% - but in the second exam I had to go over the allotted time by a fair bit to finish.
Anyway - for $10, Enthuware is such good value and I've learnt heaps from reading the explanations and testing them. I want to nail the OCJA then go on to the OCJP
Here is a bit of code comparing (seemingly) incompatible objects with the instanceof operator.
My question - sure - I can understand why String and Date are incompatible; likewise, Random and Date, but why aren't HashMap and Date incompatible?
the compiler doesn't seem to mind this line:
Code: Select all
System.out.println(m instanceof Date);
Code: Select all
import java.util.Map;
import java.util.HashMap;
import java.util.Date;
import java.util.Random;
public class Stuff {
public static void main(String[] args) {
Map m = new HashMap();
String s = new String();
Random r = new Random();
System.out.println(m instanceof Date); //compatible - why ??
System.out.println(s instanceof Date); //incompatible types
System.out.println(r instanceof Date); //incompatible types
}
}