jeudi 16 juillet 2020

How to retrieve implementations of Interfaces using Java Reflection at runtime [duplicate]

I have an interface and an implementation as below.

interface IDataType {}

class DataTypeImpl implements IDataType{
    String str = "Value";
}

I'll get the interface name at Runtime. And I need to retrieve the field from implementation.

Class<?> cls = Class.forName("IDataType");

Is there any way to retrieve the implementation class of this interface? Anything I can use with this cls object?

Please Note: I need to use Java 6 only. I know its possible in Java 8 using Reflections class.





Aucun commentaire:

Enregistrer un commentaire