tags:

views:

75

answers:

2

I'm looking for the correct syntax for the following:

public class Foobar<K extends SomeJavaAPIClass and implements Cloneable>{

So that I can have Foobars of 'K', where K is a generic subclass of SomeJavaAPIClass and where K has it's own clone() method

I've tried <K extends SomeJavaAPIClass, implements Cloneable> with no luck, along with other permutations

+8  A: 

Use &:

public class Foobar<K extends SomeJavaAPIClass & Cloneable> {

Note that in generic wildcards, "extends" just means "is a subtype of", so you use it for either classes or interfaces.

Laurence Gonsalves
+3  A: 

I think the following is valid:

public class Foobar<K extends SomeJavaAPIClass & Cloneable> {

As far as I know "extends" is used for both classes and interfaces in generic declarations. Would someone else care to comment?

Alex Stoddard