>> I want to allocate a new object of type T.
>
> The type T is not known at run-time
> Therefore, it can not be used at run-time.
This makes sense; thanks. Your use of the Factory class confused me a
bit; were you suggesting that I create an extra auxiliary class in order
to create the objects?
As an alternative to what I think you were suggesting, I'm going to try
passing the parameterizing class as a parameter to the constructor,
which is logically redundant with using the parameter in the first
place. This will be stored in the object, and will let me use the
newInstance method.
The actual statement that I'm using to invoke the constructor is now:
Maze m = new Maze<TriangleCell> (nRows, nColumns,
mazeFrame.getContentPane(), TriangleCell.class);
It compiles; I don't yet have enough program in place to see if it works.
Thanks again for your help.
Bruce
Stefan Ram - 23 Oct 2006 03:58 GMT
>passing the parameterizing class as a parameter to the constructor,
>which is logically redundant with using the parameter in the first
>place. This will be stored in the object, and will let me use the
>newInstance method.
A class might be abstract or might lack a proper (default)
constructor, so the availability of a newInstance-method can
not be checked statically.
Bruce Feist - 23 Oct 2006 04:07 GMT
>> passing the parameterizing class as a parameter to the constructor,
>
> A class might be abstract or might lack a proper (default)
> constructor, so the availability of a newInstance-method can
> not be checked statically.
And so I might get a run-time error. For this application, I can deal
with that as a trade-off with the complexity of using an auxiliary
factory class. If I were writing a package for commercial distribution
I'd rethink that, but I'm likely to be the only one ever using this.
Or maybe I'm just being lazy...
Bruce