• Post Reply Bookmark Topic Watch Topic
  • New Topic

nongenerics+generics  RSS feed

 
Sawan Mishra
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above code Set created by non-generics which may contain
String,Animal,Integer is passed by doStuff(s1) method call
but received by doStuff(Set<Number> s)
I know,in the dostuff(Set<Number> s) method I'm not allowed
to add any object on to that Set but still then
why is this feature allowed???
Set of Animal is passed and received by Set<Number>,it doesn't make any
sense...
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is for backward compatibility for working with old version of Java application.
So, you are allowed to mix Generics with Raw type.
If you work on pure Generics, compiler with do the checking for you at compile time.
But type erasure removes type information at runtime.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!