H
Hendrik Maryns
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
As said before, as a pastime, I am generifying bit by bit the Jakarta
Commons Collections. (And a bit more, i.e. also add annotations, enums,
foreach-loops).
I encountered a difficult problem and was hoping for some help here.
There is the class PrototypeFactory, which has static inner class
PrototypeSerializationFactory. What the last one does, is take an
Serializable in its constructor, and produce a clone of it each time its
create() method is invoked, using serialization.
The most obvious choice in generifying it is to make it like this:
static class PrototypeSerializationFactory<T extends Serializable>
implements Factory<T>, Serializable
It creates a T every time create() is invoked. Accordingly, the
constructor takes a T as argument, where this used to be Serializable:
private PrototypeSerializationFactory(T prototype) {
super();
iPrototype = prototype;
}
This works fine. Until I want to invoke its constructor...
Because this constructor is invoked in a rather complicated method which
does some tests on an argument like:
does the argument have a clone() method -> return PrototypeCloneFactory
does it have a public constructor -> return a factory which uses the
constructor
only if both options above fail, comes the test:
is it instanceof Serializable -> return new
PrototypeSerializationFactory((Serializable)arg).
The obvious choice in generifying seems to make that
return new PrototypeSerializationFactory<T>(arg),
where arg is of type T (which is in turn the type parameter of the
generic method).
But this gives the following error:
Bound mismatch: The type T is not a valid substitute for the bounded
parameter <T extends Serializable> of the type PrototypeFactory.
PrototypeSerializationFactory<T>
I understand this: T is unbound. But is there some way to sort of cast
the type parameter? Because I am sure T is indeed an extension of
Serializable...
I fear something like passing a Class parameter will be necessary. Ideas
welcome...
Cheers, H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEjus/e+7xMGD3itQRAj/mAJsEKXfPl97iDSUnyAPBIeHmzGysRwCfZz9t
KAzB6Gz5/LdqUkQysSkDkHI=
=pA0v
-----END PGP SIGNATURE-----
Hash: SHA1
Hi,
As said before, as a pastime, I am generifying bit by bit the Jakarta
Commons Collections. (And a bit more, i.e. also add annotations, enums,
foreach-loops).
I encountered a difficult problem and was hoping for some help here.
There is the class PrototypeFactory, which has static inner class
PrototypeSerializationFactory. What the last one does, is take an
Serializable in its constructor, and produce a clone of it each time its
create() method is invoked, using serialization.
The most obvious choice in generifying it is to make it like this:
static class PrototypeSerializationFactory<T extends Serializable>
implements Factory<T>, Serializable
It creates a T every time create() is invoked. Accordingly, the
constructor takes a T as argument, where this used to be Serializable:
private PrototypeSerializationFactory(T prototype) {
super();
iPrototype = prototype;
}
This works fine. Until I want to invoke its constructor...
Because this constructor is invoked in a rather complicated method which
does some tests on an argument like:
does the argument have a clone() method -> return PrototypeCloneFactory
does it have a public constructor -> return a factory which uses the
constructor
only if both options above fail, comes the test:
is it instanceof Serializable -> return new
PrototypeSerializationFactory((Serializable)arg).
The obvious choice in generifying seems to make that
return new PrototypeSerializationFactory<T>(arg),
where arg is of type T (which is in turn the type parameter of the
generic method).
But this gives the following error:
Bound mismatch: The type T is not a valid substitute for the bounded
parameter <T extends Serializable> of the type PrototypeFactory.
PrototypeSerializationFactory<T>
I understand this: T is unbound. But is there some way to sort of cast
the type parameter? Because I am sure T is indeed an extension of
Serializable...
I fear something like passing a Class parameter will be necessary. Ideas
welcome...
Cheers, H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEjus/e+7xMGD3itQRAj/mAJsEKXfPl97iDSUnyAPBIeHmzGysRwCfZz9t
KAzB6Gz5/LdqUkQysSkDkHI=
=pA0v
-----END PGP SIGNATURE-----