Re: Method chaining with generics
- From: "Hemal Pandya" <hemalpandya@xxxxxxxxx>
- Date: 31 Aug 2005 04:24:37 -0700
Chris Uppal wrote:
> Raymond DeCampo wrote:
>
> > Is there any case
> > when casting a List to List<Object> would cause a problem?
>
> I haven't been following the thread, so this may be irrelevant. But if you
> start with a List that is intended to hold Strings (whether it's declared as a
> List or a List<String> doesn't matter provided it reaches your code as a List)
> and cast that to a List<Object>, then you'll be able to add a Rectangle to it,
> which would not be correct.
Very true. There are two different cases depending on how the List
started. If it was intended to hold Strings but created as a List, not
a List<String> then the error is at the point of creation. This issue
exists in all java until 5.0. If it was created as a List<String> then
the error is where it was converted to List.
But given a List, which by definition is a list of Objects, is there a
case where casting it to List<Object> is dangerous?
.
- Follow-Ups:
- Re: Method chaining with generics
- From: Oliver Wong
- Re: Method chaining with generics
- References:
- Method chaining with generics
- From: iksrazal
- Re: Method chaining with generics
- From: Hemal Pandya
- Re: Method chaining with generics
- From: Oliver Wong
- Re: Method chaining with generics
- From: Raymond DeCampo
- Re: Method chaining with generics
- From: Chris Uppal
- Method chaining with generics
- Prev by Date: Re: Method chaining with generics
- Next by Date: Duplex socket receiving data too fast?
- Previous by thread: Re: Method chaining with generics
- Next by thread: Re: Method chaining with generics
- Index(es):
Relevant Pages
|
|