• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TypeSafety

 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, This is from Whizlabs..Code, question and my assumptions are given below. Please advice.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How will this line compile? List is an interface, there is no new keyword and its missing brackets at the end.

For answer 1 and 2 I agree with you.
You can never instantiate a wildcard type, this is why this line doesn't compile.
The 2nd line doesn't compile as aa might not have been initialized. Otherwise it compiles fine which makes answer 3 correct...
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit, assignment means, option2 at Line 42 is assigning at Line 26 "list" reference variable (or) reference variable "aa" at line 54 is assigning to bb (or) both ?
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically when you pass some variables in a method call, its not assignment. But most of the rules that apply to assignment will apply to it. So in this case, rules of generics apply to both line 54 and 42...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic