Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why am able to pass a Set (non-generic) to a method expecting Set<Number>?

 
Archna Singh
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Its a question from Kathy Sierrs Practice book, Q 58 Practice Set 3. Why its compiled properly??? A HashSet is passed to a Set<Number>. Should it compile?

The answer mentioned is 2 0 1 0 1 false
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
backward compatibility .

think you have clients(say A and B) who are using your method *print(Set setObj)* .

and after some time you upgrade your method as print(Set<Integer> setObj) .

in this situation you should not force your client to change their code as your wish. what if the client B doesn't have sufficient money to change his code?
 
Arhaan Singhania
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Archana,

Please use code tags while posting the code as it is not easy to understand the snippet other wise.

Arhaan
 
Rahul Choudhary
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Archna Singh, I happen to ask the same question a few days back. You'll find the answer in the second post of this thread:
Why it's possible to pass Non gen set to a method expecting Set<Number>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic