2

Is there anyway to use a bounded wildcard require a class implement more than one interface?

In otherwords, something like...

class Foo<S extends Comparable && Clonable>

...which would require that objects extend both interfaces?

I realize I can make another ComparableAndClonable which extends the two but I don't have control over some of the code (So I can't go make my future-S object implement ComparableAndClonable).

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
Pace
  • 41,875
  • 13
  • 113
  • 156
  • For the record, `S` is a [bounded type parameter](https://docs.oracle.com/javase/tutorial/java/generics/bounded.html), not a [bounded wildcard](https://docs.oracle.com/javase/tutorial/java/generics/wildcards.html). – shmosel Feb 18 '16 at 22:06

1 Answers1

3
class Foo<S extends Comparable & Clonable>

Should work.

See Java Generics Wildcarding With Multiple Classes for further info.

[1]:

Community
  • 1
  • 1
Martin
  • 7,089
  • 3
  • 28
  • 43