January 5, 2010

Java instanceof operator

instanceof checks true runtime values. So, the following code would print:


Object o = new LinkedList();
if(o instanceof LinkedList)
System.out.println("yep");


This is not the same behavior as method lookup (find the fancy name for this). This example would produce an error:


List theList = new Queue();
theList.enqueue(new Object());

No comments:

Post a Comment