Connecting Tech Pros Worldwide Forums | Help | Site Map

generics: how to tell more about the parameter?

Mikhail Teterin
Guest
 
Posts: n/a
#1: Jun 27 '08
Hi!

I'd like to promise certain things about the parameter of a generic:

public class Foo<Bar implements Something{
...
}

but that's a syntax error immediately -- javac expects a closing `>' right
where the space after `Bar' is in the above example...

How can I do this -- so that I can rely on Bar's features inside Foo and
have the compiler enforce the possible Bar's compliance?

Thanks!

-mi

Joshua Cranmer
Guest
 
Posts: n/a
#2: Jun 27 '08

re: generics: how to tell more about the parameter?


Mikhail Teterin wrote:
Quote:
Hi!
>
I'd like to promise certain things about the parameter of a generic:
>
public class Foo<Bar implements Something{
...
}
how about:

public class Foo<Bar extends Something{

Note that this works if `Something' is a class or if it is an interface.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Closed Thread