In java, we can narrow the return type and the throws exception type (or even erase the throws clause) :
abstract class A
{
abstract CharSequence getName() throws NameNotAvailableException;
}
class B extends A
{
String getName()
{
return "foo";
}
}
But, what about parameter types (if A takes a T
, then why not B takes ? super T
) as in :
abstract class A
{
abstract void setName(final String name);
}
class B extends A
{
void setName(final CharSequence name)
{
}
}
Let's consider this piece of code which i think is completely logical to me :
void handleA(final A a)
{
a.setName("foo");
}
handleA(new B());
So what i'm saying is that B
is still valid in the context of code using A
.