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?


Ray

--
XML is the programmer's duct tape.
.



Relevant Pages

  • Re: Method chaining with generics
    ... >> The warning says that the runtime environment can't actually tell ... >> whether the cast succeeds or not, so basically, the ... This makes incremental migration of code from 1.4 to 5 rife with ...
    (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)
  • Re: Why are not we allowed to create arrays of genetic container?
    ... This is one of the rare cases where the coice to implement Generics through Type Erasure leaves you no way to express your intention in a type safe manner, hence you cannot avoid using @SuppressWarningsto write code, that doesn't issue errors or warnings: ... You can reason that the suppressed uncheck warning doesn't apply, because there are no Elements in the newly created array, that could violate the unchecked cast. ... As to "Why" Sun did not allow a special sugared syntax for this common case of parametrized arrays, ...
    (de.comp.lang.java)