Re: Defining a constructor in an Interface
- From: Chris Berg <spam.spam.eggs@xxxxxxx>
- Date: Thu, 30 Jun 2005 13:54:17 +0200
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
.
- References:
- Defining a constructor in an Interface
- From: Chris Berg
- Defining a constructor in an Interface
- Prev by Date: Re: Defining a constructor in an Interface
- Next by Date: Re: To class or to method
- Previous by thread: Re: Defining a constructor in an Interface
- Next by thread: JFrame Resize Issues
- Index(es):
Relevant Pages
|