This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

List

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
List<Integer> ls1 = new LinkedList(); //line 1
List<String> ls2 = new LinkedList(); //line 2
List ls3 = new LinkedList(); //line 3
List ls4 =ls1; //line 4
List ls5 =ls2; //line 5
List ls6=ls5=ls4; //line 6


which line(s) contains error?
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
List<Integer> ls1 = new LinkedList<Integer>(); //line 1
List<String> ls2 = new LinkedList<String>(); //line 2
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ed Thompson,

Do U say that the lines 1 & 2 give error? Can U let me know the cause?
 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i believe both curly bracket on ref and obj sides have to be the same.

but what the, what about line 6???
is it even legal?
 
Ed Thompson
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just plugged it into a class in Eclipse and let it complain.

The warning I got was a Type Safety warning:
"Type safety: The expression of type LinkedList needs unchecked conversion to conform to List<Integer>"

Beyond that I got no errors.

 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy,

all lines compile fine.

Only 1 and 2 will compile with a warning. Because you assigned a generic variable to a non-generic object. Allowed, compiles nicely, but you get a warning.


Yours,
Bu.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic