And thus spoke Fred Kleinschmidt...
> This seems to be a bit silly. In the code above, you say:
> Test t = (Test)Class.forName(...).....
>
> Why not just
> Test t = new Test(...);
> And thus spoke Fred Kleinschmidt...
>
[quoted text clipped - 8 lines]
>
> Because sometimes you just have the name of the class as a String.
But then you do not know beforehand that the string is "Test",
so how can you know that it is legal to cast it to a Test?
And if you do klnow beforehand that it is guaranteed to be
a Test, why not just use
test t = new Test();
and dispense with parsing a name that you already know will
be "Test".
My comment was to show that you can create a Test instance
only if you know that the argument to forName() is the name of
the Test class or one of its subclasses.
Thus you use
Class c = Class.forName()
and check the results to see if it really is a Test. Otherwise
your code may throw an illegal cast exception.
>> That is, since you declare 't' to be of type Test, you already
>> must have information about that class from some import.
>
> Of course, it's just a simplified example, nothing more. :-)

Signature
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Flo 'Irian' Schaetz - 04 Jan 2007 21:37 GMT
And thus spoke Fred Kleinschmidt...
> But then you do not know beforehand that the string is "Test",
> so how can you know that it is legal to cast it to a Test?
[quoted text clipped - 3 lines]
> and dispense with parsing a name that you already know will
> be "Test".
Normaly you will not randomly create instances of classes :-) So it's
more likely, that you get the name of a class as a string, for example,
that is supposed to implement, for example, a specific interface.
> My comment was to show that you can create a Test instance
> only if you know that the argument to forName() is the name of
> the Test class or one of its subclasses.
Of course you have to test many details. But again: It's just a
simplified example, I didn't write the exception and I didn't think it
was needed to specify all tests. I am rather sure, that Knute didn't
want to do it like Test t = ... :-)
Flo