Re: What is "evil" about casting?

From: Jacob (jacob_at_yahoo.com)
Date: 09/29/04


Date: Wed, 29 Sep 2004 16:37:30 +0200

Jonck wrote:

> Today I was reading through some discussions about the new functionality
> in Java 1.5 and there I read more than once that casting was considered
> "evil" and that generics would solve all this (or not, as others argued).
>
> Could someone give me a brief explenation as to what is wrong with
> casting and how generics in Java 1.5 will solve this? Personally I don't
> see what's wrong with casting, in all the books I've read on Java casts
> are used all the time...

Casting may cause errors that are not caught until runtime.
Purists wants as many errors as possible to be caugth during
compilation.

I've never understood the fuss about it. It is peanuts
compared to the extensive XML-"programming" and SQL-processing
which is common inside Java programs nowdays.

Actually I prefer the simple error prone "classic" syntax over
the more robust (but more complex) Generics syntax.



Relevant Pages

  • Re: Box and UnBoxing
    ... > I assume it's the same as in Java and then it's not similar to casting. ... > Boxing creates a new instance of a different class, ... Shayne Wissler ...
    (comp.object)
  • Re: What is "evil" about casting?
    ... > see what's wrong with casting, in all the books I've read on Java casts ... The problem with casting is that it results in runtime exceptions. ... Generics makes Collections typesafe *and* convenient ...
    (comp.lang.java.programmer)
  • Re: Array Help!?!?!?...
    ... but I'm sure it can be done somehow, ... possibly by casting it to some generic type. ... Or perhaps that's the Java in ...
    (microsoft.public.word.vba.general)
  • Re: What is "evil" about casting?
    ... > in Java 1.5 and there I read more than once that casting was considered ... They then must cast, ... but they require the developer to know the type of object he ...
    (comp.lang.java.programmer)
  • Re: Open letter to sun about java generics syntax
    ... can easily be added to Java 1.4. ... If you look at java code on the server (face it, ... List of (List of String) ... just as using "<" in generics syntax does NOT ...
    (comp.lang.java.programmer)