Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dan new collections

 
tony kanvas
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

dan said The first method call, m(null,null), calls method m with two null literals that have type null. Both null literals are promoted to type B because B is more specific than type A
but if you see A its same as B why compiler take B
 
John Paverd
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine the following class hierarchy:
class Animal {}
class Mammal extends Animal {}
class Horse extends Mammal {}
This makes it a bit easier to see that a sub class is more specific than a super class. Any horse is an animal, but not every animal is a horse.
JLS section 15.12.2.2 has more information about choosing the most specific method:
The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error.
 
Abu Yoosuf
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tony kanvas:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic