Hi there, I have two classes named Address and Person. I also make one instance for Address and one instance for Person. Then I have the following code: Person p = new Person(); Address a = new Address(); if(p instanceof Person) ...... if(a instanceof Address) .... if(a instance of Person) //check ..... When I compile, it gave me error "inconvertible types found : com.berkley.training.util.Person required: com.berkley.training.util.Address if(p instanceof Address)" I am not sure why it is a compile error instead of run-time error. Thanks! qionghua ^
You have no more the compiler error. I think that the compiler check for easy instanceof test before compiling. But i don't know much about the compiler behaviour! if someone know better ! let explain ------------------ Benjamin l�onard www.evisor.com [This message has been edited by Benjamin Leonard (edited May 22, 2001).]
If a cast of the RelationalExpression to the ReferenceType would be rejected as a compile-time error, then the instanceof relational expression likewise produces a compile-time error.
qhyang, Please change your name to be compliant with JavaRanch's naming policy. Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name. Thanks, Cindy
"JavaRanch, where the deer and the Certified play" - David O'Meara