您好!欢迎来到北极熊

北极熊

热门搜索: 任正非传    神雕侠侣    红楼梦   

java方法参数中通配符如何使用

分类:软件开发应用 时间:2022-11-29 20:15 浏览:120
概述
说明1、通配符? super Frui限定了泛型下界为 Fruit。2、Generic<Fruit>对象和Generic<Food>对象可以作为参数传递给print2。但是Generic<Apple>对象不能作为参数传入,因为 Apple是Fruit的子类,超出了泛型规定的下界。实例 JavaScriptGeneric<Fruit> fruitGeneric2 
内容

说明

1、通配符? super Frui限定了泛型下界为 Fruit。

2、Generic<Fruit>对象和Generic<Food>对象可以作为参数传递给print2。但是Generic<Apple>对象不能作为参数传入,因为 Apple是Fruit的子类,超出了泛型规定的下界。

实例

 JavaScript

Generic<Fruit> fruitGeneric2 = new Generic<>(); print2(fruitGeneric2); 
  Generic<Food> foodGeneric2 = new Generic<>(); print2(foodGeneric2); 
  //    错误使用 //    Generic<Apple> appleGeneric2 = new Generic<>(); //    print2(appleGeneric2);



评论
资讯正文页右侧广告
联系我们
电话:18936411277
邮箱:1044412291@qq.com
时间:09:00 - 19:00
公众号:北格软件
底部广告