Forums Register Login

Parameterized Types

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1038 times.
Similar Threads
Difference between Arguments and parameters
Can I caste Object[] to String[]?
Is this a bug?
datatypes in java
declarations with <> operator with classes like S , T , K, V, M, B
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:41:16.