Re: Defining a constructor in an Interface



I'm overwelmed by the responses, thanks, all.

For one thing, I made an error i the originals post:

String newClassName = "mypackage.MyInterface";

should read

String newClassName = "mypackage.MyClass";
// (class that implements MyInterface)

This has made some confusion, sorry about that.

On the other hand, solving this particular problem would not make me
happy, I can see that now. As the class name comes from the
user/implementor at run-time, is could be erroneous in a number of
ways:

- specify a non-existing class file
- specify a file that is not a valid .class file
- specify a class that does not implement the interface
- specify a class that does implement the interface, but that lacks
one or more of its methods (possible if he made his own version of the
interface - unlikely, but possible).

If I choose the default-constructer-plus-init-method solution, I'm
still not home free.

The real reason why I want to specify a specific constructor is that
the Exception thrown during construction is difficult to descipher by
the user, resulting in me getting lots of "What does this error mean"
e-mails.

So I guess the solution lies elsewhere, I see that now: I must make a
better exception handler, telling the user more about what has
happened.

BUT! It would be nice to have a sort of 'run-time class file verifyer'
that could verify a class file BEFORE you try to instantiate it. That
would really make my day!

Chris

.



Relevant Pages

  • Re: STILL Need help w. Java Networking.
    ... This advice has been provided to you on many occasions already. ... so the class file will end up here: ... When you want to run the class, you have to specify the current ...
    (comp.lang.java.programmer)
  • Re: Java Native Interface problems
    ... >> The class file and the java file both contain information that indicate ... specifying SpeechIO is correct as that is specify cw.speech implicitly. ... I've got the program working again and I'm thankful for the ... Stephen Kellett ...
    (comp.lang.java.programmer)
  • Re: Jar
    ... return an InputStream which you can use to read the file. ... The first one allows you to specify the location inside the jar file, the second one assumes the "resource" file is located in the same package where the .class file is located. ...
    (comp.lang.java.programmer)
  • Re: JNI Problem
    ... But anyway, just a question, why do we explicitly have to specify the ... classpath for it? ... error: cannot access InvokeMasterCom ... class file contains wrong class: ...
    (comp.lang.java.programmer)
  • Re: Applets and custom class loaders
    ... Just put the class file on the server in the ... Since it is not in the Jar ... Class.forNameto load an interface implementation to ... therefore the whole idea of delayed loading a class might not be worse ...
    (comp.lang.java.gui)