Hi all,
This question concerns the use of the Class.getSuperClass() method.
Situation:
abstract class Parent
abstract class Child extends from Parent
class GrandChild extends Child
Using GrandChild.getSuperClass() gives me the Parent class.
If this is intended i am surprised but fair enough.
The question is: how do i a hold of the Child class in a similar
fashion? I.e. how can i tell from which class the GrandChild extends
directly (so only 1 level up the tree rather than n levels).
I hope i described the issue correctly ;-)
TIA
Fermin DCG
VisionSet - 16 Apr 2004 22:37 GMT
> Hi all,
>
[quoted text clipped - 7 lines]
> Using GrandChild.getSuperClass() gives me the Parent class.
> If this is intended i am surprised but fair enough.
No, it gets the direct ascendent, 'Child' should be returned.
--
Mike W
Bryce (Work) - 16 Apr 2004 23:18 GMT
>Hi all,
>
[quoted text clipped - 7 lines]
>Using GrandChild.getSuperClass() gives me the Parent class.
>If this is intended i am surprised but fair enough.
You must have specified it wrong. I just tried the following:
Parent.java:
public abstract class Parent {
}
Child.java:
public abstract class Child extends Parent{
}
GrandChild.java:
public class GrandChild extends Child{
public static void main(String [] args) {
System.out.println(GrandChild.class.getSuperclass().getName());
}
}
Running GrandChild give me:
Child
Using: j2sdk1.4.2_03
--
now with more cowbell
Roedy Green - 18 Apr 2004 00:24 GMT
>Using GrandChild.getSuperClass() gives me the Parent class.
That is surprising. Could you post your complete code, or convert your
code to a tiny app that demonstrates this strange behaviour.
Maybe you accidentally in your cut/paste wrote:
GrandChild extends Parent
instead of
GrandChild extends Child
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.