Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, Type Variables' bounds can only be present in the Type Variable declaration, right?

Type Variables' bounds can only appear in the declaration of classes, interface, methods and constructors?

Or can I bound a type variable when they are used as type arguments?

Edit: Example:

class MyClass<T extends Number> { // T is bounded by the interface Number
    // can a bounded Type Parameter appear anywhere else,
    // besides the Type parameter declaration?
}
like image 566
John Assymptoth Avatar asked May 30 '26 08:05

John Assymptoth


1 Answers

The Java Language Specification seems to agree with you:

A type variable (§4.4) is an unqualified identifier. Type variables are introduced by generic class declarations (§8.1.2) generic interface declarations (§9.1.2) generic method declarations (§8.4.4) and by generic constructor declarations (§8.8.4).

like image 188
Michael Borgwardt Avatar answered May 31 '26 23:05

Michael Borgwardt