Comma or ampersand with multiple bounded types?

As others have pointed out, this:

class MyOtherClass <T extends OtherInterface & SomeInterface>

defines a multiply bounded type parameter. If you use MyOtherClass, you must give it a type that implements both OtherInterface and SomeInterface.

However, this does not define a multiply bounded type parameter:

class MyClass <T extends OtherInterface, SomeInterface>

It defines a generic with two type parameters. The first one must implement OtherInterface. The second one can be anything. It’s just the same as

class MyClass <T extends OtherInterface, U>

except that you named it SomeInterface instead of U. (The convention is that type parameters are normally single upper-case letters, or sometimes an upper-case letter and a digit or a short upper-case identifier. But the compiler doesn’t care. It won’t look at the form of the identifier to figure out that you really meant it as an interface.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)