Home | Contents | Latest | Previous | Next

That Recursive Java Generics Thing....

From: "andrew cooke" <andrew@...>

Date: Tue, 10 Jan 2006 19:06:58 -0300 (CLST)

SelfBounded<T extends SelfBounded<T>>

At last - a clear explanation.  From Bruce Eckel, at Artima.

http://www.artima.com/weblogs/viewpost.jsp?thread=136394
http://www.artima.com/forums/flat.jsp?forum=106&thread=136394
(second link includes comments)

Comments:

It's the ability to specify "this argument should be 'just like me', even
after subclassing", that is only expressible by self-bounded generics.
[...]
A self-bounded type is not a self-type. It's a common misconception that
self-bounded types are equivalent to self-types. See the "Generics and
covariant return types" post# 8 for example of this.

A self-bounded type cannot guarantee that the argument will be the same
type as this after subclassing. There is no equivalent to self-types in
Java generics.
[...]
self-bounding types are to enable covariant argument types.

And a link to explain that -
http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)

Andrew

Comment on this post