Connecting Tech Pros Worldwide Help | Site Map

generics: how to tell more about the parameter?

  #1  
Old June 27th, 2008, 05:17 PM
Mikhail Teterin
Guest
 
Posts: n/a
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
  #2  
Old June 27th, 2008, 05:17 PM
Joshua Cranmer
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
any alternatives to (lack of) virtual static functions? =?Utf-8?B?Y2FybG0=?= answers 10 December 14th, 2007 05:35 PM
Generic methods phancey@googlemail.com answers 10 August 24th, 2007 06:35 PM
Alternatives to the C++ Standard Library? Steven T. Hatton answers 43 July 23rd, 2005 06:52 AM
To bean or not to bean Steven T. Hatton answers 61 July 22nd, 2005 07:59 PM