C
Chris Berg
An interface forces the implementor to write the code for all the
(abstract) methods. Fine. But can I also enforce a specific
constructor footprint?
Maybe it sounds silly, but it isn't: I am constructing objects using
reflection, for instance:
String newClassName = "mypackage.MyInterface";
// (actually a run-time parameter, not a constant)
Class[] clss = new Class[]{java.util.Properties.class};
Class clazz = Class.forName(newClassName);
Constructor constr = clazz.getConstructor(clss);
MyInterface myObject = (MyInterface)constr.newInstance(objss);
So, I want to make sure that the new class actually has a constructor
with the given parameter(s).
I don't think I can use a static factory method, 'cause that would
require an actual instance of the class, which I don't have, I just
have it's name. Dilemma!
(PLEASE, ALL! Don't start a long thread with pro's and con's about
reflection, that is NOT the point here!)
Chris
(abstract) methods. Fine. But can I also enforce a specific
constructor footprint?
Maybe it sounds silly, but it isn't: I am constructing objects using
reflection, for instance:
String newClassName = "mypackage.MyInterface";
// (actually a run-time parameter, not a constant)
Class[] clss = new Class[]{java.util.Properties.class};
Class clazz = Class.forName(newClassName);
Constructor constr = clazz.getConstructor(clss);
MyInterface myObject = (MyInterface)constr.newInstance(objss);
So, I want to make sure that the new class actually has a constructor
with the given parameter(s).
I don't think I can use a static factory method, 'cause that would
require an actual instance of the class, which I don't have, I just
have it's name. Dilemma!
(PLEASE, ALL! Don't start a long thread with pro's and con's about
reflection, that is NOT the point here!)
Chris