Java method get the inheriting type
Posted
by DrDro
on Stack Overflow
See other posts from Stack Overflow
or by DrDro
Published on 2010-05-11T07:25:40Z
Indexed on
2010/05/11
7:44 UTC
Read the original article
Hit count: 250
I have several classes that extend C and I would need a method that accepts any argument of type C. But in this method I would like to know if I'm dealing with A or B.
*
public A extends C
public B extends C
public void goForIt(C c)()
If I cast how can I retrieve the type in a clean way (I just read using getClass or instanceof is often not the best way).
PS: Fell free to edit an explicit title.
*Sorry but I can't type closing braces
© Stack Overflow or respective owner