• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameterized Types  RSS feed

 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JLS, 4.5 Parameterized Types

A parameterized type consists of a class or interface name C and an actual type argument list <T1 , ... , Tn>. It is a compile time error if C is not the name of a generic class or interface, or if the number of type arguments in the actual type argument list differs from the number of declared type parameters of C. In the following, whenever we speak of a class or interface type, we include the generic version as well, unless explicitly excluded. Throughout this section, let A1 , ... , An be the formal type parameters of C, and let be Bi be the declared bound of Ai. The notation [Ai := Ti] denotes substitution of the type variable Ai with the type Ti, for 1in, and is used throughout this specification.

Let P = G<T1, ..., Tn> be a parameterized type. It must be the case that, after P is subjected to capture conversion (�5.1.10) resulting in the type G<X1, ..., Xn>, for each actual type argument Xi, 1in , Xi <: Bi[A1 := X1, ..., An := Xn] (�4.10), or a compile time error occurs.

Discussion
Example: Parameterized types.



I don't understand this at all. Is there a way that I can run this abstruse example?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
Use the simplest and probably most popular Collection type, and try this sort of thing:-I have just thrown all this lot together in a couple of minutes, but I think it will work, and show you the simplest use of parametrised types.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JLS snippets aren't much of an example. It's more of an illustration of what parameterized types look like.

Try this generics article, which includes a link to a generics tutorial.
[ July 21, 2006: Message edited by: marc weber ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!