Java method: retrieve 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/17 8:10 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

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).

*Sorry but I can't type closing braces

© Stack Overflow or respective owner

Related posts about java

Related posts about beginner