tag:blogger.com,1999:blog-741750605858169835.post3247771853350278428..comments2024-01-24T14:53:02.919+00:00Comments on Stephen Colebourne's blog: Generics and commons-collectionsStephen Colebournehttp://www.blogger.com/profile/01454237967846880639noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-741750605858169835.post-38505597813572153272006-06-17T21:09:32.000+01:002006-06-17T21:09:32.000+01:00> What's the point of non-generic code in t...> What's the point of non-generic code in this day and age? <br /><br />Well, a lot of large enterpises are still running JDK1.3 (or even earlier) and perfectly happy. If you work in a small agile environent you can get a completely different view of the Java world from the enterprise view.Stephen Colebournenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-861090247494057712006-06-17T19:06:34.000+01:002006-06-17T19:06:34.000+01:00What's the point of non-generic code in this d...What's the point of non-generic code in this day and age?<br /><br />I guess it's probably worth cleaning up the API at the same time. It is absolutely huge. And, obviously, keep it in line with changes to java.util.Tom Hawtinhttp://jroller.com/page/tackline/noreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-72606506189566018462006-06-17T15:30:02.000+01:002006-06-17T15:30:02.000+01:00+10000 for generics!
We now have almost all our c...+10000 for generics!<br /><br />We now have almost all our code based on generics and we would be pleased to see them in commons-collections as well.Arik Kfirnoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-57236158192942168292006-06-17T15:00:48.000+01:002006-06-17T15:00:48.000+01:00I never liked the idea of Generics right from the ...I never liked the idea of Generics right from the get-go. Looking at them and reading about them, there was just something that rubbed me up the wrong way. That was until I started to actually use them. Now, I'm totally in love (mostly). Looking at it in the context of one example like that given above is just useless. The compile time error stuff is nice and all, but there is just so much more. It's difficult to explain, but they change the way you code in a lot of circumstances. Combined with the other additions in 1.5 (like the enhanced for-loop etc...) it just comes together in a way that you can never really appreciate until you've spent some time working seriously with them.<br /><br />Give it a go.timhttp://tim.littlebluefrog.comnoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-77561441641516043572006-06-17T03:27:03.000+01:002006-06-17T03:27:03.000+01:00Yeah, well, I did say that Java's implementati...Yeah, well, I did say that Java's implementation was backwards. :) I still think they're slightly better than not having them at all, though.<br /><br />A combination of this and C# 3.0-style type-inference could really be nice, actually.Jess Sightlerhttp://www.jroller.com/page/jsight/noreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-58722689590167854152006-06-16T23:06:44.000+01:002006-06-16T23:06:44.000+01:00I think the last example sums up the lack of benef...I think the last example sums up the lack of benefit. Instead of typing String once, you now have to type it three times. And those angle brackets just give you headaches.<br /><br />Sure you when you get something wrong you'll get a compile error, but big deal. The whole point is that generics tries to solve something that wasn't a problem in the first place (CCEs are actually very rare).Stephen Colebournenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-90475360218535204492006-06-16T19:05:08.000+01:002006-06-16T19:05:08.000+01:00Pre-Generics:
List stringList = new ArrayList();
s...Pre-Generics:<br />List stringList = new ArrayList();<br />stringList.add("hello");<br />stringList.add(new Integer(5));<br /><br />Iterator iter = stringList.iterator();<br />while (iter.hasNext()) {<br /> String str = (String)iter.next();<br />}<br /><br />Compiles Ok! Runtime error though... oops.<br /><br />Post Generics:<br />List stringList = new ArrayList();<br />stringList.add("hello");<br />stringList.add(new Integer(5));<br />Iterator iter = stringList.iterator();<br />while (iter.hasNext()) {<br /> String str = iter.next();<br />}<br /><br />Compile error!<br /><br />So the benefit is typesafety at compile time instead of runtime.<br /><br />Of course, the Java implementation is so backwards that typesafety isn't particularly guaranteed. Oh well.Jess Sightlerhttp://www.jroller.com/page/jsight/noreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-82354333387588533272006-06-16T16:10:34.000+01:002006-06-16T16:10:34.000+01:00Since there are so many pro-generics posters hover...Since there are so many pro-generics posters hovering about, how about somebody link to an article/blog entry that describes what they are and how they are useful. I read the Java5 release notes about them, but did not find that explanation very helpful. I'm still using Java 1.4.x on a project, and am very happy with it. Somebody help me understand what I'm missing, if you happen to be familiar with a good resource. Thanks.Thane Speedynoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-31246179848724516172006-06-16T13:59:50.000+01:002006-06-16T13:59:50.000+01:00Yes, please move to generics. Just make sure it i...Yes, please move to generics. Just make sure it is handled such that we can have both versions in the classpath at the same time easily. :)Jess Sightlerhttp://www.jroller.com/page/jsight/noreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-15780279299851967432006-06-16T13:51:42.000+01:002006-06-16T13:51:42.000+01:00i think all the commons projects should switch to ...i think all the commons projects should switch to Java 5 and leave the current versions as managable branches. Not only generics but all Java 5 stuff should be used. Especially concurrent classes makes many commons objects obsolete..afsinanoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-49164893370355866322006-06-16T10:16:06.000+01:002006-06-16T10:16:06.000+01:00Definitely FOR an implementation of commons-collec...Definitely FOR an implementation of commons-collection with generics support.<br />Of course, such an implementation already exists, but having it under the Apache Commons hat would allow to insure consistency between Java 1.x and Java 5+ implementations at a minimal cost, no ?<br /><br />P.S.: John, did you have a look at Groovy ? It offers Ruby-like features (closures are so powerful) along with full Java support. Quite interesting indeed.Guillaume Ghttp://www.jroller.com/page/junglewarenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-55645997590123482872006-06-16T07:48:22.000+01:002006-06-16T07:48:22.000+01:00I am in favour of generics.
Using libraries based...I am in favour of generics. <br />Using libraries based on generics is easy, writing generics library is another pair of stuff of course. <br />And for what concerns the 433 pages of the generics FAQ, I think for an average developer the shorter SUN "Generics Tutorial" (there's a PDF on the net) is quite enough to start.Alessio Pacehttp://www.jroller.com/page/alessiopacenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-82162421678208035092006-06-16T02:16:53.000+01:002006-06-16T02:16:53.000+01:00A huge YES for having the collections updated to m...A huge YES for having the collections updated to make use of generics. I've been using one of the forks for about a year or so, and I can't live without it. Code is vastly more readable as a result of using generics. Yes, there are some complexities. Yes erasure is unfortunate. But let's not throw the baby out with the bathwater.<br /><br />I would not use the official Apache version anymore if it weren't for all the projects I do use which have it as a dependency. I've had no issues with http://larvalabs.com/collections/, and from my perspective, it is a huge improvement on the official version.Gill Batesnoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-36536096948517327172006-06-16T01:27:32.000+01:002006-06-16T01:27:32.000+01:00Hi Stephen,
I'm a fan of Ruby and the "c...Hi Stephen,<br /><br />I'm a fan of Ruby and the "closure" style of programming it encourages.<br /><br />I had a spell where I was using a lot of the CollectionUtils methods with inline anonymous classes to try to program that way in Java. In the end I quit that and returned to using the Java 5 enhanced for loop instead, because of all the extra casting required with CollectionUtils.<br /><br />I've started playing around with the collections15 fork and it seems like CollectionUtils is a lot nicer to use in it. I'm not sure yet whether I will use this a lot, but it is a step closer to "Java, the way I want it".<br /><br />John HurstJohn Hurstnoreply@blogger.com