Heritage Bug in Java?

Hi there...

do you know how it is possible to do the following (I assume it is not....). Let's say class A is a Java-intern class such as String...

class B extends A{

.....

}

so lateron I use a Java-intern method, that returns an array of all A's constructed.

How can I test if some of these A's are B's?

the matter is, that I can't use B's methods on A....

does someone know how to solve that problem?

thx

Charly

[493 byte] By [JebeDiAH] at [2007-9-26 1:25:41]
# 1
I *think* I understand what you want:try this:if(object instanceof B) {object.aMethodOfBOnly();}
esmo at 2007-6-29 1:07:31 > top of Java-index,Archived Forums,Java Programming...
# 2
Actually you first need to cast the object to B: "(B) object.aMethodOfBOnly();". The instanceof-comparison is good to be there because you would get a ClassCastException if the object didn't happen to be an instance of B.
jsalonen at 2007-6-29 1:07:31 > top of Java-index,Archived Forums,Java Programming...
# 3
correct indeed :)try this:if(object instanceof B) {((B)object).aMethodOfBOnly();}
esmo at 2007-6-29 1:07:31 > top of Java-index,Archived Forums,Java Programming...