Re: Method chaining with generics




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?

.



Relevant Pages

  • Re: autorefresh?
    ... you may be able to split up strings. ... Altrus ... Having two side by side sections, each section pulling data from ... :> Of course, depending on the type of data, you may wish to adjust the ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Duplicate entries in drop down box
    ... Depending on what kind of thread it is (a worker thread for example) you ... message to window that owns the combo and having it add the strings for you. ... You can pass a reference or pointer to the string in the parameter so long ...
    (microsoft.public.vc.mfc)
  • Re: Method chaining with generics
    ... >> Raymond DeCampo wrote: ... If it was intended to hold Strings but created as a List, ... Hence the warning in the compiler. ...
    (comp.lang.java.programmer)
  • Re: Playing Standing Up
    ... If I'll be standing at the gig, ... the saying that "form follows function" applies ... Depending on what you're playing, contorting the body or reposition the ... instrument to better reach the strings is a must. ...
    (alt.guitar.beginner)
  • Re: _T() return LPCTSTR?
    ... design bug by allowing quoted strings to be writeable, you certainly hold more than enough qualifications to do so. ... depending on the compilation environment. ... context MSDN and I think the ISO standard define multibyte to include 8-bit character strings. ...
    (microsoft.public.vc.mfc)