Re: What is "evil" about casting?
From: Scott Ellsworth (scott_at_alodar.com)
Date: 09/30/04
- Next message: dd711: "XML String Manipulation <--- Have somebody can help me?"
- Previous message: Jacob: "Re: Division by zero: float vs. int"
- In reply to: Jonck: "What is "evil" about casting?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Sep 2004 21:52:20 -0700
In article <20040929160644123+0200@news.text.chello.nl>,
Jonck <jonck@vanderkogel.net> wrote:
> Hi all,
> 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).
They cut out some expressiveness. Before 1.5, the Collections API used
only generic Objects. Programmers thus had no easy way to know what
they are going to get back out. They then must cast, and if they get it
wrong, or if an infrequently used code path puts something they do not
expect into the collection. they get a class cast exception.
> 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...
They work, but they require the developer to know the type of object he
or she is trying to get out of the Collection. As a developer, I would
rather state that the collection vends/accepts Actions, or Forms, or
whatever, than make the end user guess.
Scott
- Next message: dd711: "XML String Manipulation <--- Have somebody can help me?"
- Previous message: Jacob: "Re: Division by zero: float vs. int"
- In reply to: Jonck: "What is "evil" about casting?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|