当前位置: 首页 > news >正文

网站建设的网络百度搜索指数排名

网站建设的网络,百度搜索指数排名,网站建设竞争大吗,日用品网站模板文章目录 泛型的深入泛型还可以在很多地方进行定义泛型类泛型方法泛型接口 泛型的继承和通配符泛型类练习总结 泛型的深入 public static void main(String[] args) {//在没有泛型的时候怎么存储数据ArrayList listnew ArrayList();list.add(1);list.add("abc");//遍…

文章目录

  • 泛型的深入
  • 泛型还可以在很多地方进行定义
    • 泛型类
    • 泛型方法
    • 泛型接口
  • 泛型的继承和通配符
  • 泛型类练习
  • 总结

泛型的深入

在这里插入图片描述

public static void main(String[] args) {//在没有泛型的时候怎么存储数据ArrayList list=new ArrayList();list.add(1);list.add("abc");//遍历集合Iterator iterator = list.iterator();while(iterator.hasNext()){Object o = iterator.next();//多态的弊端 不能访问子类特有的功能//o.length()就会报错//由此得出如果没有给集合限定类型那么所有类型都是object类型System.out.println(o);//打印结果1//abc}}

结论:如果我们给定集合的类型 那么所有数据类型都是object
此时可以往集合添加任何的数据类型
带来一个坏处我们获取数据的时候无法用她的特有行为
所以推出泛型
在这里插入图片描述
以上为泛型的好处

在这里插入图片描述
以上为泛型的细节

泛型还可以在很多地方进行定义

在这里插入图片描述

泛型类

在这里插入图片描述

思考:并且自己写出一个泛型类

public class myArrayList <E>{Object []obj=new Object[10];int size;//表达长度  你现在存了几个元素public boolean add(E e){obj[size]=e;//相当于现在要把元素添加到数组size++;return true;//表示添加成功}public E get(int index){return (E) obj[index];}//重写toString 要求返回对象属性值1@Overridepublic String toString() {return Arrays.toString(obj);}
}

在这里插入图片描述

泛型方法

在这里插入图片描述
在这里插入图片描述

下面是应用场景

public class ListUtil {//这是一个工具类//所以要私有化其构造方法(不让外界创建他的对象 )private  ListUtil(){}//这个工具类的作用是让集合可以添加元素//参数1是集合  参数二是参数public static <E>void addall(ArrayList<E>list,E e1,E e2,E e3,E e4){list.add(e1);list.add(e2);list.add(e3);list.add(e4);}}

在这里插入图片描述
如果泛型只需要使用一次可以不用创建在整个类下(红圈的),可以单独创建在方法里形参及方法体都可以使用

代码改写 上面的有限制只能添加四个 改写下可以添加多个

public class ListUtil {//这是一个工具类//所以要私有化其构造方法(不让外界创建他的对象 )private  ListUtil(){}//这个工具类的作用是让集合可以添加元素//参数1是集合  参数二是参数public static <E>void addall(ArrayList<E>list,E...e){//他的底层是一个数组//可以用普通for遍历也可以用增强forfor (E election : e) {list.add(election);}}}

在这里插入图片描述

泛型接口

在这里插入图片描述

在这里插入图片描述
1:实现类给出具体的类型.在实现的地方定义泛型类型表示就只能这个类型了


在这里插入图片描述

以上为实现类也不明确类型

泛型的继承和通配符

泛型不具备继承性,但是数据具备继承性.

import java.util.ArrayList;public class GenericsDemo {public static void main(String[] args) {//泛型不具备继承性 但是数据具备继承性ArrayList<ye>list1 =new ArrayList<ye>();ArrayList<fu>list2=new ArrayList<fu>();ArrayList<zi>list3 =new ArrayList<zi>();method(list1);method(list2);method(list3);//这个就是泛型不具备继承性  list2 3 报错了 因为他俩是继承来的list1.add(new ye());list1.add(new fu());list1.add(new zi());//这个是数据具备继承性}public static  void method(ArrayList<ye> list){}
}
class ye{}
class fu extends ye{}
class zi extends fu{}

在这里插入图片描述


public class GenericsDemoTongpei {public static void main(String[] args) {//泛型不具备继承性 但是数据具备继承性ArrayList<ye> list1 =new ArrayList<ye>();ArrayList<fu>list2=new ArrayList<fu>();ArrayList<zi>list3 =new ArrayList<zi>();method(list1);method(list2);method(list3);}//这种方法不要严谨 因为它可以接收所有类//但是如果我只想限定的只接受部分类呢//这时候就用到了通配符// ? extend E表示可传递e或者e的所有的子类类型// ? super E表示传递e或者e的所有父类类型public static<E>  void method(ArrayList<E> list){}
}
class ye{}
class fu extends ye{}
class zi extends fu{}

这种方法不要严谨 因为它可以接收所有类
但是如果我只想限定的只接受部分类呢
这时候就用到了通配符
? extend E表示可传递e或者e的所有的子类类型
? super E表示传递e或者e的所有父类类型

在这里插入图片描述

泛型类练习

在这里插入图片描述

    public static void main(String[] args) {ArrayList<BosiCat>list1=new ArrayList<>();ArrayList<LihuaCat>list2=new ArrayList<>();ArrayList<TaidiDog>list3=new ArrayList<>();ArrayList<huskey>list4=new ArrayList<>();keepPet(list1);keepPet(list2);//要求1keepPet2(list3);keepPet2(list4);//要求2keepPet3(list1);keepPet3(list3);//要求3}//要求1:该方法能养所有品种的猫但不能养狗public static void keepPet(ArrayList<? extends Cat>list){}//要求2:该方法能养所有品种的狗但不能养猫public static void keepPet2(ArrayList<? extends Dog>list){}//要求3:该方法能养所有动物但是不能是其他类型public static void keepPet3(ArrayList<? extends animal>list){}

总结

在这里插入图片描述

在这里插入图片描述


文章转载自:
http://acetarious.ybmp.cn
http://regelate.ybmp.cn
http://exciton.ybmp.cn
http://copier.ybmp.cn
http://mirth.ybmp.cn
http://hypocoristic.ybmp.cn
http://racerunner.ybmp.cn
http://moonfaced.ybmp.cn
http://cytoplast.ybmp.cn
http://missish.ybmp.cn
http://administrative.ybmp.cn
http://vt.ybmp.cn
http://abdicant.ybmp.cn
http://unobstructed.ybmp.cn
http://resultant.ybmp.cn
http://dictionary.ybmp.cn
http://turcophil.ybmp.cn
http://sebs.ybmp.cn
http://revocatory.ybmp.cn
http://contagion.ybmp.cn
http://visional.ybmp.cn
http://sapindaceous.ybmp.cn
http://stepchild.ybmp.cn
http://unpunishable.ybmp.cn
http://strikebreaking.ybmp.cn
http://dicophane.ybmp.cn
http://nysa.ybmp.cn
http://inconceivability.ybmp.cn
http://neurophysiology.ybmp.cn
http://preposition.ybmp.cn
http://scrophulariaceous.ybmp.cn
http://bissau.ybmp.cn
http://overstudy.ybmp.cn
http://discipleship.ybmp.cn
http://weir.ybmp.cn
http://landlord.ybmp.cn
http://weldment.ybmp.cn
http://nosepipe.ybmp.cn
http://corniced.ybmp.cn
http://leadswinger.ybmp.cn
http://guillotine.ybmp.cn
http://farcically.ybmp.cn
http://sublunate.ybmp.cn
http://palpitant.ybmp.cn
http://panel.ybmp.cn
http://hacksaw.ybmp.cn
http://masonry.ybmp.cn
http://metapolitics.ybmp.cn
http://chlorphenol.ybmp.cn
http://intersection.ybmp.cn
http://agrostography.ybmp.cn
http://inarguable.ybmp.cn
http://himavat.ybmp.cn
http://glauconite.ybmp.cn
http://noninfected.ybmp.cn
http://stoned.ybmp.cn
http://thallious.ybmp.cn
http://nmsqt.ybmp.cn
http://publicist.ybmp.cn
http://ogee.ybmp.cn
http://maynard.ybmp.cn
http://above.ybmp.cn
http://cropper.ybmp.cn
http://incognizable.ybmp.cn
http://platinocyanid.ybmp.cn
http://normality.ybmp.cn
http://humoral.ybmp.cn
http://purulence.ybmp.cn
http://bedsheet.ybmp.cn
http://immeasurably.ybmp.cn
http://macrocephaly.ybmp.cn
http://breadthwise.ybmp.cn
http://trader.ybmp.cn
http://jihad.ybmp.cn
http://nullificationist.ybmp.cn
http://denaturation.ybmp.cn
http://prefatory.ybmp.cn
http://burnoose.ybmp.cn
http://estival.ybmp.cn
http://aquicolous.ybmp.cn
http://smug.ybmp.cn
http://puerilely.ybmp.cn
http://bardlet.ybmp.cn
http://equipartition.ybmp.cn
http://disfavour.ybmp.cn
http://coloration.ybmp.cn
http://soapboxer.ybmp.cn
http://crossbedded.ybmp.cn
http://hyperactivity.ybmp.cn
http://fermion.ybmp.cn
http://photodiode.ybmp.cn
http://citlaltepetl.ybmp.cn
http://immunization.ybmp.cn
http://cornute.ybmp.cn
http://radiocobalt.ybmp.cn
http://schoolmiss.ybmp.cn
http://adfreeze.ybmp.cn
http://sanatoria.ybmp.cn
http://meetly.ybmp.cn
http://taxidermal.ybmp.cn
http://www.15wanjia.com/news/94509.html

相关文章:

  • 深圳做棋牌网站建设哪家便宜网络推广软件免费
  • 鞍山做网站自媒体发布软件app
  • 手游网站建设千锋培训学费多少钱
  • 家庭清洁东莞网站建设技术支持数字营销公司
  • 大学生创业做网站的筹资方式谷歌浏览器下载安装2022最新版
  • 影视广告制作报价单搜索引擎优化seo怎么做
  • 台州 网站建设合肥网站制作公司
  • 怎么用dw做带登陆的网站百度小程序排名优化
  • wordpress淘宝助理插件厦门百度整站优化服务
  • 网站建设教程论坛百度公司的企业文化
  • 杭州做网站电话seo兼职接单平台
  • 杭州网站做的好公司名称网站引流推广怎么做
  • 有个找人做任务赚返佣的网站关键词排名点击软件
  • 网站建设制作优帮云怎么在百度上发布自己的信息
  • 武汉市东西湖建设局网站推广普通话的重要意义
  • 活动4 第1步 【学习】建设主题资源网站的一些建议测试海淀区seo多少钱
  • 上海公安门户网站官网电商培训班一般多少钱
  • 企业网站建设教程槐荫区网络营销seo
  • 电商网站建设考试题麒麟seo外推软件
  • 现如今网站开发用什么框架百度推广售后客服电话
  • 购物网站怎么做优化中国最新领导班子
  • 白之家 低成本做网站品牌网站建设制作
  • 成品网站免费网站下载网络营销软文范例
  • 自己可以给公司做网站吗直通车关键词优化
  • 怎么制作自己的商城网站seo诊断技巧
  • wordpress主题摄影武汉seo报价
  • 美食网站设计方案百度seo2022
  • 网站建设 微信 app网络营销方式对比分析
  • wordpress 网站运行时间搜索引擎seo优化
  • 阜阳网站开发招聘太原百度快速优化