Re: Multiple template classes with different parameter lists
David R Tribble <david@tribble.com> writes:
Is it possible to delare multiple classes with the same name, each
taking a different number of template parameters?
The parameters are erased for the JVM, so it looks like
an illegal redeclaration to the JVM.
It would be possible, if the declarations were in two
different classes or packages:
class H { static class A<S>{} }
class I { static class A<S,T>{} }
Sometimes, when interfaces with different numbers of
parameters are wanted, one starts to declare the interface
with the maximum number of parameters, for example:
interface A<S,T> { .... }
Then an interface with a smaller number of parameters is
derived from this by substituting a ?dummy argument? for
the parameter not wanted, for example:
interface A1<S> extends A<S,java.lang.Object> {}
For example, this technique was used by Ralf Ullrich in
<xn0f8wdvwkbmpps00b@news.online.de>
http://groups.google.com/group/de.comp.lang.java/msg/0b32b202f65760cc?hl=de&dmode=source&output=gplain
(the first three interface declarations)
(FWIW, you can do this sort of thing in C++, but that's a whole
nuther can of worms.)
(Thanks for ?Incompatibilities Between ISO C and ISO C++?!)