Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
reply
    Bookmark Topic Watch Topic
  • New Topic