<?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: Usability and Java 1.5 generics vs. Autocasting</title> <atom:link href="http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/feed/" rel="self" type="application/rss+xml" /><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/</link> <description>Rants about Java and other internet technologies by Sam Pullara</description> <lastBuildDate>Wed, 18 Jan 2012 14:14:00 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>By: spullara</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-1004</link> <dc:creator>spullara</dc:creator> <pubDate>Fri, 13 Mar 2009 07:09:35 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-1004</guid> <description>You are totally missing the point on the example. There is no opportunity for doing what you suggest with JNDI because the common &#039;interface&#039; is Object and actually may not have any commonality at all.</description> <content:encoded><![CDATA[<p>You are totally missing the point on the example. There is no opportunity for doing what you suggest with JNDI because the common &#39;interface&#39; is Object and actually may not have any commonality at all.</p> ]]></content:encoded> </item> <item><title>By: Chris</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-1003</link> <dc:creator>Chris</dc:creator> <pubDate>Fri, 13 Mar 2009 03:28:44 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-1003</guid> <description>I think the point you are missing is that what you call a &quot;mixed map&quot; can often be folded into a generic through the use of an interface; wrap the elements of your map in an interface that abstracts the functionality that binds them together into a single map in the first place. Then you declare the generic map using the interface as the element type. &lt;br&gt;&lt;br&gt;This has the side effect that you must make explicit in the API the design decisions behind why the elements are in the same map, thus self-documenting the features of the underlying connectivity between the pieces. This was part of the goal with generics. An object-oriented purist would say that anytime you are forced to cast you are missing an opportunity for polymorphism. Unfortunately the Java 1.4 Collections API forced you to cast just to use the most basic features.&lt;br&gt;&lt;br&gt;In Java 1.5 we are closer to the ideal, which is that you should see every cast as an opportunity to add polymorphism.</description> <content:encoded><![CDATA[<p>I think the point you are missing is that what you call a &#8220;mixed map&#8221; can often be folded into a generic through the use of an interface; wrap the elements of your map in an interface that abstracts the functionality that binds them together into a single map in the first place. Then you declare the generic map using the interface as the element type.</p><p>This has the side effect that you must make explicit in the API the design decisions behind why the elements are in the same map, thus self-documenting the features of the underlying connectivity between the pieces. This was part of the goal with generics. An object-oriented purist would say that anytime you are forced to cast you are missing an opportunity for polymorphism. Unfortunately the Java 1.4 Collections API forced you to cast just to use the most basic features.</p><p>In Java 1.5 we are closer to the ideal, which is that you should see every cast as an opportunity to add polymorphism.</p> ]]></content:encoded> </item> <item><title>By: spullara</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-945</link> <dc:creator>spullara</dc:creator> <pubDate>Fri, 13 Mar 2009 00:09:35 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-945</guid> <description>You are totally missing the point on the example. There is no opportunity for doing what you suggest with JNDI because the common &#039;interface&#039; is Object and actually may not have any commonality at all.</description> <content:encoded><![CDATA[<p>You are totally missing the point on the example. There is no opportunity for doing what you suggest with JNDI because the common &#39;interface&#39; is Object and actually may not have any commonality at all.</p> ]]></content:encoded> </item> <item><title>By: Chris</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-944</link> <dc:creator>Chris</dc:creator> <pubDate>Thu, 12 Mar 2009 20:28:44 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-944</guid> <description>I think the point you are missing is that what you call a &quot;mixed map&quot; can often be folded into a generic through the use of an interface; wrap the elements of your map in an interface that abstracts the functionality that binds them together into a single map in the first place. Then you declare the generic map using the interface as the element type. &lt;br&gt;&lt;br&gt;This has the side effect that you must make explicit in the API the design decisions behind why the elements are in the same map, thus self-documenting the features of the underlying connectivity between the pieces. This was part of the goal with generics. An object-oriented purist would say that anytime you are forced to cast you are missing an opportunity for polymorphism. Unfortunately the Java 1.4 Collections API forced you to cast just to use the most basic features.&lt;br&gt;&lt;br&gt;In Java 1.5 we are closer to the ideal, which is that you should see every cast as an opportunity to add polymorphism.</description> <content:encoded><![CDATA[<p>I think the point you are missing is that what you call a &#8220;mixed map&#8221; can often be folded into a generic through the use of an interface; wrap the elements of your map in an interface that abstracts the functionality that binds them together into a single map in the first place. Then you declare the generic map using the interface as the element type.</p><p>This has the side effect that you must make explicit in the API the design decisions behind why the elements are in the same map, thus self-documenting the features of the underlying connectivity between the pieces. This was part of the goal with generics. An object-oriented purist would say that anytime you are forced to cast you are missing an opportunity for polymorphism. Unfortunately the Java 1.4 Collections API forced you to cast just to use the most basic features.</p><p>In Java 1.5 we are closer to the ideal, which is that you should see every cast as an opportunity to add polymorphism.</p> ]]></content:encoded> </item> <item><title>By: spullara</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-824</link> <dc:creator>spullara</dc:creator> <pubDate>Thu, 08 Jan 2009 21:59:41 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-824</guid> <description>Amusingly, generics in Java don&#039;t prevent you from using the wrong key type, here is some legal code that fails at runtime:&lt;br&gt;&lt;br&gt;    Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();&lt;br&gt;    map.put(&quot;test&quot;, &quot;test&quot;);&lt;br&gt;    StringBuilder sb = new StringBuilder(&quot;test&quot;);&lt;br&gt;    String a = map.get(sb);  // works fine, returns null, no error at compile time.&lt;br&gt;&lt;br&gt;So even they do not prevent some kinds of errors that could be statically prevented.  IntelliJ will warn you about that one though.</description> <content:encoded><![CDATA[<p>Amusingly, generics in Java don&#39;t prevent you from using the wrong key type, here is some legal code that fails at runtime:</p><p> Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();<br
/> map.put(&#8220;test&#8221;, &#8220;test&#8221;);<br
/> StringBuilder sb = new StringBuilder(&#8220;test&#8221;);<br
/> String a = map.get(sb);  // works fine, returns null, no error at compile time.</p><p>So even they do not prevent some kinds of errors that could be statically prevented.  IntelliJ will warn you about that one though.</p> ]]></content:encoded> </item> <item><title>By: Krish</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-823</link> <dc:creator>Krish</dc:creator> <pubDate>Thu, 08 Jan 2009 19:35:44 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-823</guid> <description>Hmmm... That putting the type checking responsibility on the developer. That&#039;s taking the main power of java (static type checking) out of the equation. In the EJB case, it&#039;s fine, because it will immediately be caught when we start testing the app.&lt;br&gt;&lt;br&gt;But in a generic Map, in big apps, if we don&#039;t rely on the compiler to do the type checking if can become a big issue in a production environment. Having said that, java till 1.4 had that hole and that&#039;s what generics avoids by strictly typing collections.&lt;br&gt;&lt;br&gt;Still there can still be uses for a mixed type maps. In those cases, your solution can reduce some clutter in the code.</description> <content:encoded><![CDATA[<p>Hmmm&#8230; That putting the type checking responsibility on the developer. That&#39;s taking the main power of java (static type checking) out of the equation. In the EJB case, it&#39;s fine, because it will immediately be caught when we start testing the app.</p><p>But in a generic Map, in big apps, if we don&#39;t rely on the compiler to do the type checking if can become a big issue in a production environment. Having said that, java till 1.4 had that hole and that&#39;s what generics avoids by strictly typing collections.</p><p>Still there can still be uses for a mixed type maps. In those cases, your solution can reduce some clutter in the code.</p> ]]></content:encoded> </item> <item><title>By: spullara</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-822</link> <dc:creator>spullara</dc:creator> <pubDate>Wed, 07 Jan 2009 18:51:56 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-822</guid> <description>The simple case where you have:&lt;br&gt;&lt;br&gt;String value = map.get(key)&lt;br&gt;&lt;br&gt;I&#039;m not looking at what was inserted into the map, merely assuming that you know what you put in the map and automatically adding a cast under the covers so the bytecode actually looks like:&lt;br&gt;&lt;br&gt;String value = (String) map.get(key)&lt;br&gt;&lt;br&gt;Similarly in the case of doing a JNDI lookup, the developer has already declared the type that is coming out of the JNDI context on the left-hand side of the assignment and the cast is just repeating yourself.</description> <content:encoded><![CDATA[<p>The simple case where you have:</p><p>String value = map.get(key)</p><p>I&#39;m not looking at what was inserted into the map, merely assuming that you know what you put in the map and automatically adding a cast under the covers so the bytecode actually looks like:</p><p>String value = (String) map.get(key)</p><p>Similarly in the case of doing a JNDI lookup, the developer has already declared the type that is coming out of the JNDI context on the left-hand side of the assignment and the cast is just repeating yourself.</p> ]]></content:encoded> </item> <item><title>By: Krish</title><link>http://www.javarants.com/2004/05/13/usability-and-java-1-5-generics-vs-autocasting/comment-page-1/#comment-821</link> <dc:creator>Krish</dc:creator> <pubDate>Wed, 07 Jan 2009 18:49:47 +0000</pubDate> <guid
isPermaLink="false">http://www.javarants.com/?p=1059#comment-821</guid> <description>Hmmm... If I follow your logic correctly, in the simple case, you know the type of the values by inspecting what is being inserted into the map. In a local map this is pretty simple to do... But what if it is a static map and values are getting inserted (retrieved) into (from) this map from all over the application code. How would you know what type you are supposed to autocast to at compile time. Generics elegantly solves that problem by letting us define the type of the collection.&lt;br&gt;&lt;br&gt;Also, in the J2EE case, how do you know the type of the EJB to autocast it to? All you have is the jndi name.</description> <content:encoded><![CDATA[<p>Hmmm&#8230; If I follow your logic correctly, in the simple case, you know the type of the values by inspecting what is being inserted into the map. In a local map this is pretty simple to do&#8230; But what if it is a static map and values are getting inserted (retrieved) into (from) this map from all over the application code. How would you know what type you are supposed to autocast to at compile time. Generics elegantly solves that problem by letting us define the type of the collection.</p><p>Also, in the J2EE case, how do you know the type of the EJB to autocast it to? All you have is the jndi name.</p> ]]></content:encoded> </item> </channel> </rss>
