Type Parameter Section of a Generic Method

Line 22 begins method printArray’s declaration. All generic method declarations have a type-parameter section (<T> in this example) delimited by angle brackets that precedes the method’s return type. Each type-parameter section contains one or more type parameters, separated by commas. A type parameter, also known as a type variable, is an identifier that specifies a generic type name. The type parameters can be used to declare the return type, parameter types and local variable types in a generic method declaration, and they act as placeholders for the types of the arguments passed to the generic method, which are known as actual type arguments. A generic method’s body is declared like that of any ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.