Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've been looking at a number of OSS java projects and a number of them still have not adopted generics. They're using raw types (e.g. List foo) instead of generic types (e.g. List<string> foo). Other projects have only begun using generics in the last few years even thought they've been around for a long time.

I'm interested to know why people and projects eschew the use of generics when there appears (to me) to be now downside in using them instead of rawtypes. For those of you who use java, but not generics, what (if anything) would make you switch?

share|improve this question
    
I don't program in Java, but one of my pet peeves is mystery containers. That is, saying List foo without making it clear what foo is a list of. –  Joey Adams Apr 25 '11 at 17:36

4 Answers 4

Some projects have to run on older JVMs. For example, some projects might not even be able to use assert yet (introduced in Java 1.4), because they still need to work on Java 1.3 JVMs.

Another factor is simply inertia: If code was already written, and performs fine without adding the use of generics, there's little reason to take the risk in changing the code. But today, there are several automatic tools to help you migrate your Java code to use generics.

share|improve this answer
1  
+1. The first reason was the reason I couldn't use generics in a project I was working on a couple of years ago. I was actually working with the latest version of Java on my development machine, but the production build machine was 1.2 (as required for that product). So I often broke the build. :) –  Bobby Tables Dec 15 '10 at 2:39

It's helpful, when trying to understand stuff like this, to think of each new release of a language as a different language. Different features, different idioms, different users...

Sure, the new version is a fairly easy language for users of the previous version to pick up... But some programmers - actually quite a few programmers - learn one language and then stop. Whether that's K&R C, late-80s C++, VB5, Java 1.4, or C# 1.1... You'll find programmers, even entire shops, who learned that one version of that one language, bought a reference book, put it on the shelf, and then set about using it. Suggesting that they spend extra time tracking and integrating each new standard into their work is only slightly less ridiculous than suggesting that they type one-handed while juggling oranges with the other, or start using Scala - it just doesn't seem necessary.

With that in mind, read: How can I introduce new technology to my team?

share|improve this answer

Another answer is that some programmers don't really understand what they're doing. Java is a very accessible language which inevitably leads to people learning it to a "usable" degree quickly and never progressing further. I know as a 16-year-old I knew enough about Java too make good everyday apps, but if I hadn't kept learning I still wouldn't know what a generic was.

share|improve this answer

This may be bad form, but I'm posting an answer as a response to Macneil's answer; I'm not able to comment everywhere yet.

I don't think that running on older JVMs would be the issue; my understanding is that generics were added to the language the way they were (with type erase) so that new code using generics could run on old JVMs. That isn't to say that the same is true of asserts, though, but that isn't what the question is about anyway.

share|improve this answer
    
The problem is, you sometimes need to compile under older compilers. So then, obviously, any generics in the code will break the build. I can't for the life of me remember why we had to do this (on a previous project) - but this was the reason we couldn't introduce generics even when newer versions of Java were out. –  Bobby Tables Dec 15 '10 at 2:53
    
Exactly what Guzica said: If you are using a modern Java compiler, you're going to be using techniques, like assert, that won't work on older JVMs. –  Macneil Dec 15 '10 at 4:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.