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 Question

 
Nikhil Shah Jain
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


And:


Does this code compile?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried to compile it ?
 
Nikhil Shah Jain
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, the answer in the mock exam is wrong.
The code does not compile.
 
Henry Wong
author
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.



Why not? What was the compile error?

Henry
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.

Really? I just tried it out and did not get any compiler errors.

Please QuoteYourSources when you copy a question from a book, mock exam or other source - tell us where this question is from.
 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.


Are you sure???
According to me it should compile, nothing invalid in it. I dont have access to jdk now so I cant really try it out now.....

In my dry run:
Code has an implementer(B) of interface(A) which correctly overrides the interface's lone method a().

and then you are adding into an ArrayList of type A something which IS-A A(ie, B)

So, I see no problem in this.
 
Mario Gimenez
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For me work fine.
Why do you say that??'
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.


The two code snaps will compile!
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiles OK here to. I ran this little prog




Everything compiled and ran fine.

Why did you think it would not compile?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic