0

I have a class called NewsDAO that extends the abstract class AbstractDAO and pass it the class News as paramether.

public class NewsDAO extends AbstractDAO<News> {
}

What I need is a method to know, starting from all classes called ***DAO, the type of class passed as paramether to AbstractDAO.

I struggled with it for a while but I didn't find the way.

Thank you

MDP
  • 4,177
  • 21
  • 63
  • 119

1 Answers1

1

You can get the full name of the class you are extending by this way:

String fullExtendedClassName = this.getClass().getGenericSuperclass()
            .toString();

Then you just have to format your string and get the info between '<' and '>'

String extendedClassName = fullExtendedClassName.substring(fullExtendedClassName.
indexOf("<") + 1, fullExtendedClassName.indexOf(">"));

Hope it helps you.

Manu AG
  • 188
  • 1
  • 6