Code Comments
Programming Forum and web based access to our favorite programming groups.Hi -
I'm trying to extend Vector. I want it to accept any generic class
that implements a particular interface.
This is my best attempt:
interface MyInterface {
}
class Type1 implements MyInterface {
}
class Type2 implements MyInterface {
}
class MyVector<T implements MyInterface> extends Vector<T> {
}
I want MyVector to accept both Type1 and Type2 as classes but nothing
else which does not implement MyInterface.
I based this code on an O'Reilly book which apparently was written
before 1.5 was released. I've also tried wildcards without luck.
Thanks in advance.
Post Follow-up to this messageOn Fri, 22 Apr 2005 18:42:07 +0100, Brian <brian@notreal.com> wrote:
> Hi -
>
> I'm trying to extend Vector. I want it to accept any generic class
> that implements a particular interface.
>
> This is my best attempt:
>
> interface MyInterface {
> }
>
> class Type1 implements MyInterface {
> }
>
> class Type2 implements MyInterface {
> }
>
> class MyVector<T implements MyInterface> extends Vector<T> {
> }
>
> I want MyVector to accept both Type1 and Type2 as classes but nothing
> else which does not implement MyInterface.
>
> I based this code on an O'Reilly book which apparently was written
> before 1.5 was released. I've also tried wildcards without luck.
>
> Thanks in advance.
Try this:
class MyVector<T extends MyInterface> extends Vector<T> {
You have to use 'extends' rather than 'implements', even with interfaces.
This one got me the first time too.
Dan.
--
Daniel Dyer
http://www.footballpredictions.net
Post Follow-up to this messageDaniel Dyer < dan@footballnospamformepleasepredictions
.net> wrote:
> Try this:
> class MyVector<T extends MyInterface> extends Vector<T> {
> You have to use 'extends' rather than 'implements', even with interfaces.
> This one got me the first time too.
> Dan.
That was it! Thanks Dan.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.