This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I need to retrieve value of a final static string in an interface. I don't know the interface name till run time. I cannot load the interface because no class implements the interface. Would you give me some suggestion? Thanks
Despite its name, the Class class can represent interfaces as well as classes. So use <pre> Class cl = Class.forName(interfaceName); Field fld = cl.getField(fieldName); String value = fld.get(null).toString(); </pre>
"I'm not back." - Bill Harding, Twister
Joined: Apr 20, 2001
Thanks for your reply. It works like a charm. I thought I need to have an empty constructor to load a class. Since interface does not contain any implementing method, I may need a class that implement this interface. After revisiting the API, it does clarify my confusion. Thanks a lot Jim Joey