java covariance

[b]Covariance[/b] means that [b]the type of arguments[/b], [b]return values[/b], or [b]exceptions[/b] of overriding methods can be subtypes of the original types.

在Java中不支持arguments(参数)的Covariance
override(继承) -- covariance of return value and/or exception

在继承时,允许 子类方法中“返回值和exception”是父类方法的 “返回值和exception” 的子类,这是override覆盖

在继承时,参数类型即使具有继承关系,那也是两个方法,是overload重载

override例子

class Parent{
Object func(Number n) throws Exception{
...
}
}

class Child extends Parent{
String func(Number n) throws SQLException {
...
}
}



overload例子

public class C {
public void func(Integer n){
}
public void func(String n){
}


参数的Covariance,属于overload

class Parent{
Object func(Number n){
...
}
}

class Child extends Parent{
Object func(Integer i) {
...
}
}
类的方法表
parent vtable
Entry 1: Object func(Number n) of Parent

child vtable
Entry 1: Object func(Number n) of Parent
Entry 2: Object func(Integer i) of Child
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值