A more egregious embodiment of your problem is this:
if ("foo" instanceof Number)
This is specified in JLS 15.20.2 instanceof type comparison operator :
RelationalExpression: RelationalExpression instanceof ReferenceType
If the conversion of the RelationalExpression to ReferenceType is rejected as a compile-time error, then the relational instanceof expression also generates a compile-time error. In such a situation, the result of the instanceof expression can never be true.
That is, since this expression expression generates a compile-time error:
(Number) "foo"
so this expression should be:
("foo" instanceof Number)
Your case is a little more subtle, but the principle is the same:
String is the last classString does not implement Cloneable- Therefore you cannot do
(Cloneable) aString - Therefore you also cannot make
aString instanceof Cloneable
polygenelubricants Mar 31 '10 at 9:41 2010-03-31 09:41
source share