<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Generics Journey Continues</title>
	<atom:link href="http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/feed/" rel="self" type="application/rss+xml" />
	<link>http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/</link>
	<description>Technology and Geek Stuff by Eric Burke</description>
	<lastBuildDate>Mon, 26 Jul 2010 14:36:32 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel Yokomizo</title>
		<link>http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/comment-page-1/#comment-3157</link>
		<dc:creator>Daniel Yokomizo</dc:creator>
		<pubDate>Mon, 17 Dec 2007 20:57:38 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/#comment-3157</guid>
		<description>The problem is that your doSomethingReading method is saying to the compiler, I require a MySet of any generic type that is a subtype of Foo. So T can be Foo or SubFoo. If T is SubFoo, it&#039;s obvious to see that it won&#039;t work (i.e. Foo can&#039;t be assigned to SubFoo without casting). To your problem compile you need the super wildcard: boolean contains(T o). With this in place MySet is saying that it can contain Foo or any supertype of i. Not much useful though.</description>
		<content:encoded><![CDATA[<p>The problem is that your doSomethingReading method is saying to the compiler, I require a MySet of any generic type that is a subtype of Foo. So T can be Foo or SubFoo. If T is SubFoo, it&#8217;s obvious to see that it won&#8217;t work (i.e. Foo can&#8217;t be assigned to SubFoo without casting). To your problem compile you need the super wildcard: boolean contains(T o). With this in place MySet is saying that it can contain Foo or any supertype of i. Not much useful though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Burke</title>
		<link>http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/comment-page-1/#comment-3147</link>
		<dc:creator>Eric Burke</dc:creator>
		<pubDate>Mon, 17 Dec 2007 17:59:43 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/#comment-3147</guid>
		<description>&quot;uproar&quot; ???</description>
		<content:encoded><![CDATA[<p>&#8220;uproar&#8221; ???</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/comment-page-1/#comment-3146</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Mon, 17 Dec 2007 17:55:36 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/#comment-3146</guid>
		<description>I&#039;m not sure that I follow what the whole uproar is about. From what I can tell, Kevin Bourrillion got off on a wrong tangent by incorrectly assuming substitutability where there is none. A Set of SubFoo cannot be substituted for a Set of Foo. If it could, then some wiseacre could add an object of type OtherSubFoo to the set.

Arrays are a special case in Java (see JLS3 4.10.3), and you can indeed substitute an array of SubFoo for an array of Foo. This is because the array element type is available to be dynamically verified at runtime. Due to type erasure, no such runtime verification is possible with Java generics.

In Scala, one can designate a type parameter as being covariant to allow this; the Scala compiler will then flag as errors any code that is not compatible with that type being covariant. Java doesn&#039;t have this feature.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure that I follow what the whole uproar is about. From what I can tell, Kevin Bourrillion got off on a wrong tangent by incorrectly assuming substitutability where there is none. A Set of SubFoo cannot be substituted for a Set of Foo. If it could, then some wiseacre could add an object of type OtherSubFoo to the set.</p>
<p>Arrays are a special case in Java (see JLS3 4.10.3), and you can indeed substitute an array of SubFoo for an array of Foo. This is because the array element type is available to be dynamically verified at runtime. Due to type erasure, no such runtime verification is possible with Java generics.</p>
<p>In Scala, one can designate a type parameter as being covariant to allow this; the Scala compiler will then flag as errors any code that is not compatible with that type being covariant. Java doesn&#8217;t have this feature.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Burke</title>
		<link>http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/comment-page-1/#comment-3133</link>
		<dc:creator>Eric Burke</dc:creator>
		<pubDate>Mon, 17 Dec 2007 13:22:25 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/#comment-3133</guid>
		<description>@Bob...that &quot;new Foo() {}&quot; was a mistake on my part. That was some leftover cruft from some experimentation I was doing. Thanks for pointing out that &lt;T extends E&gt; boolean contains(T o); is equivalent...that didn&#039;t really occur to me, but seems obvious now that you state it.</description>
		<content:encoded><![CDATA[<p>@Bob&#8230;that &#8220;new Foo() {}&#8221; was a mistake on my part. That was some leftover cruft from some experimentation I was doing. Thanks for pointing out that &lt;T extends E> boolean contains(T o); is equivalent&#8230;that didn&#8217;t really occur to me, but seems obvious now that you state it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Lee</title>
		<link>http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/comment-page-1/#comment-3117</link>
		<dc:creator>Bob Lee</dc:creator>
		<pubDate>Mon, 17 Dec 2007 09:37:32 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/#comment-3117</guid>
		<description>FWIW, this:

  &lt;T extends E&gt; boolean contains(T o);

is equivalent to this:

  boolean contains(E o);

i.e. I can already pass in any sub type of E.

&quot;new Foo() {}&quot; effectively creates a new anonymous sub type of Foo which does not extend SubFoo. The compiler can&#039;t let us pass a &quot;new Foo() {}&quot; to a method which expects a SubFoo. Incidentally, it can&#039;t let us pass in a plain old Foo to a method which expects a SubFoo either. The problem is, the compiler doesn&#039;t really know what ? is. It has to play it safe because it doesn&#039;t know whether ? is Foo or SubFoo, and it doesn&#039;t know how the method we&#039;re calling will use that object.</description>
		<content:encoded><![CDATA[<p>FWIW, this:</p>
<p>  &lt;T extends E&gt; boolean contains(T o);</p>
<p>is equivalent to this:</p>
<p>  boolean contains(E o);</p>
<p>i.e. I can already pass in any sub type of E.</p>
<p>&#8220;new Foo() {}&#8221; effectively creates a new anonymous sub type of Foo which does not extend SubFoo. The compiler can&#8217;t let us pass a &#8220;new Foo() {}&#8221; to a method which expects a SubFoo. Incidentally, it can&#8217;t let us pass in a plain old Foo to a method which expects a SubFoo either. The problem is, the compiler doesn&#8217;t really know what ? is. It has to play it safe because it doesn&#8217;t know whether ? is Foo or SubFoo, and it doesn&#8217;t know how the method we&#8217;re calling will use that object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse</title>
		<link>http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/comment-page-1/#comment-3094</link>
		<dc:creator>Jesse</dc:creator>
		<pubDate>Mon, 17 Dec 2007 04:52:36 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/12/16/generics-journey-continues/#comment-3094</guid>
		<description>Your example ever-so-slightly changes the contract for the contains() method. This code compiles with Set, but not with MySet. It&#039;s reasonable code in both cases:
  MySet collections = ...
  collections.add(Collections.singletonList(&quot;A&quot;));
  Iterable a = Collections.singletonList(&quot;A&quot;);
  collections.contains(a);</description>
		<content:encoded><![CDATA[<p>Your example ever-so-slightly changes the contract for the contains() method. This code compiles with Set, but not with MySet. It&#8217;s reasonable code in both cases:<br />
  MySet collections = &#8230;<br />
  collections.add(Collections.singletonList(&#8221;A&#8221;));<br />
  Iterable a = Collections.singletonList(&#8221;A&#8221;);<br />
  collections.contains(a);</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.310 seconds -->
