This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics Doubt

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! Is this declaration perfectly legal? Thanks!

List<Integer> ls1 = new LinkedList();
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi guys! Is this declaration perfectly legal? Thanks!

List<Integer> ls1 = new LinkedList();


Hi Sam,

Yeah that is legal, but with compile time warning. ls1 is typesafe reference variable of List parameterized with Integer and on the right hand
side you are creating non type safe LinkedList;

Assigning unsafe object to typesafe reference variable gives compiler warning.



Regards,
cmbhatt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic