TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Have Generics Killed Java?

1 pointsby mellisalmost 15 years ago

3 comments

gillsalmost 15 years ago
Er...[if you have the misfortune of being paid to work in Java] they remove a pile of type-casting cruft and make code more useful to large and/or transient teams.<p>The author conveniently glosses over the type-casting from pre-generics Java and instead compares to Ruby. Duh...of course Ruby is a cleaner read. But compare learning a new API:<p><pre><code> // pretty evil List&#60;Thing&#62; getTheThings(); // really evil List getTheThings(); </code></pre> Or iteration:<p><pre><code> // pretty evil for (Thing t: getTheThings()) {...} // kill me now for (Iterator it = getTheThings().iterator(); it.hasNext()) { Thing t = (Thing) it.next(); ... }</code></pre>
mfukaralmost 15 years ago
They provide more type safety and not syntactic sugar. One cannot have complete type safety at runtime using type casts; if he thinks he can, he needs to take a simple programming course again.<p>If the OP wanted readability, he could use iterators. It's amazingly clear:<p><pre><code> private void printCollection(Collection c) { Iterator&#60;String&#62; i = c.iterator(); while(i.hasNext()) { System.out.println("Item: "+i.next()); } }</code></pre>
mhdalmost 15 years ago
There's just no real alternative to generics in Java. It's either that, casting (terminally insecure) or a more modern type system, which would be a huuuge change for the language (and in which case, you might as well use Scala).<p>If you want to complain about things that make code harder to understand, I wonder why the author doesn't rant about annotations.