Re: Method chaining with generics





> Oliver Wong wrote:
> > "Hemal Pandya" <hemalpandya@xxxxxxxxx> wrote in message
> > news:1125423582.687861.85530@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> >>Actually I don't quite understand why cast from List to List<Object> is
> >>a warning at all.
> >
> >
> > The warning says that the runtime environment can't actually tell
> > whether the cast succeeds or not (due to type erasure), so basically, the
> > code that you wrote down is not actually hapenning. I think that warrants a
> > warning.
> >
>
> I think your point is valid when dealing with List and List<Foo>, but
> Hemal was specifically referring to List<Object>. Is there any case
> when casting a List to List<Object> would cause a problem?

Yes, precisely. I considered if auto-boxing could cause a problem but
am unable to come up with an example.

This makes incremental migration of code from 1.4 to 5 rife with
warnings. Until I have migrated all my code and the third party code
has migrated to using generics.

The reason I like this warning better is that I can filter it out in
javac using "grep -v".

.



Relevant Pages

  • Re: Method chaining with generics
    ... The warning says that the runtime environment can't actually tell whether the cast succeeds or not (due to type erasure), so basically, the code that you wrote down is not actually hapenning. ...
    (comp.lang.java.programmer)
  • Re: Method chaining with generics
    ... > Actually I don't quite understand why cast from List to Listis ... The warning says that the runtime environment can't actually tell ... Prev by Date: ...
    (comp.lang.java.programmer)