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

上海个人医疗网站备案东莞seo网络优化

上海个人医疗网站备案,东莞seo网络优化,淘宝上网站建设靠谱吗,java购物网站开发Java中,泛型用于编译阶段限制集合中元素的类型,或者限制类中某个属性的类型,编译过程中发生类型擦除,最终还是Object类型。 1. 集合中的泛型 集合默认可以存储任何类型的元素,即Object类型,当使用一个集合…

Java中,泛型用于编译阶段限制集合中元素的类型,或者限制类中某个属性的类型,编译过程中发生类型擦除,最终还是Object类型。

1. 集合中的泛型

集合默认可以存储任何类型的元素,即Object类型,当使用一个集合存储String类型元素时

不使用泛型
        List list = new ArrayList();list.add("a");// 当使用集合中的元素时,需要手动进行类型转换String str0 = (String) list.get(0);// 而且无法保证集合的正确性list.add(123);// 运行时报错类型转换异常 ClassCastExceptionString str1 = (String) list.get(1);
使用泛型
        List<String> list = new ArrayList<>();list.add("a");// 当使用集合中的元素时,通过泛型可以确定,集合中都是指定类型,故不需要手动进行类型转换String str0 = list.get(0);// list.add(123); // 编译不通过

2. 类中泛型

类中使用泛型与集合中同理,使用泛型可以避免使用时的手动强制转换,并保证数据的合法性。

不使用泛型
    public static void main(String[] args) {Box box = new Box("abc");String value = (String) box.getValue();box.setValue(123);// 运行时报错类型转换异常 ClassCastExceptionvalue = (String) box.getValue(); }static class Box {private Object value;public Box(Object value) {this.value = value;}public Object getValue() {return value;}public void setValue(Object value) {this.value = value;}}
3. 使用泛型
    public static void main(String[] args) {Box<String> box = new Box<>("abc");String value = box.getValue();// box.setValue(123); 编译不通过}static class Box<T> {private T value;public Box(T value) {this.value = value;}public T getValue() {return value;}public void setValue(T value) {this.value = value;}}

3. ?和 extends 和 super

? 表示不确定的类型,通常配置 extends 或 super,限制泛型的范围

    public static void main(String[] args) {// <? extends Animal>List<? extends Animal> extendsList = new ArrayList<>();// List<? extends Animal> 只允许读取,因为集合中的元素肯定是Animal或其子类Animal animal = extendsList.get(0); // List<? extends Animal> 不允许新增,因为只知道集合中的元素肯定是Animal或其子类,但无法确定类型的下限// extendsList.add(new Cat()); // <? super Animal>List<? super Animal> supperList = new ArrayList<>();// List<? super Animal> 允许新增Animal的子类,因为集合中的元素肯定是Animal或其父类supperList.add(new Cat());// List<? super Animal> 不允许读取为Animal,因为集合中的元素肯定是Animal或其父类类,但无法确定类型的上限// Animal animal = supperList.get(0); // 但是可以读取为Object,因为Object是所有类的父类Object object = supperList.get(0); // 通配符?List<?> list = new ArrayList<>();// List<?> 相当于 List<? extends Object>,只允许读取为Object,不允许新增list.get(0);}static class Animal {}static class Cat extends Animal {}static class Dog extends Animal {}

参考

https://blog.csdn.net/anlian523/article/details/1008655385538


文章转载自:
http://dinncoerythorbate.zfyr.cn
http://dinncochanty.zfyr.cn
http://dinncocoralline.zfyr.cn
http://dinncomed.zfyr.cn
http://dinncowillemstad.zfyr.cn
http://dinncoesop.zfyr.cn
http://dinncomanageable.zfyr.cn
http://dinncoshininess.zfyr.cn
http://dinncospatial.zfyr.cn
http://dinncopudendum.zfyr.cn
http://dinncohavildar.zfyr.cn
http://dinncohairtician.zfyr.cn
http://dinncomellifluous.zfyr.cn
http://dinncoretrolental.zfyr.cn
http://dinncopigsticking.zfyr.cn
http://dinncopenuche.zfyr.cn
http://dinncosonorize.zfyr.cn
http://dinncoheterozygous.zfyr.cn
http://dinncogalenism.zfyr.cn
http://dinncochange.zfyr.cn
http://dinncoreprographic.zfyr.cn
http://dinncoirani.zfyr.cn
http://dinncoisker.zfyr.cn
http://dinnconoteworthily.zfyr.cn
http://dinncocade.zfyr.cn
http://dinncopatavinity.zfyr.cn
http://dinncosublet.zfyr.cn
http://dinncokapellmeister.zfyr.cn
http://dinncooxysalt.zfyr.cn
http://dinncozizith.zfyr.cn
http://dinncodisbursable.zfyr.cn
http://dinncoplantaginaceous.zfyr.cn
http://dinncodiffusive.zfyr.cn
http://dinncosmutch.zfyr.cn
http://dinncoardency.zfyr.cn
http://dinncodeterminist.zfyr.cn
http://dinncoepiscope.zfyr.cn
http://dinncoresplendent.zfyr.cn
http://dinncocentrad.zfyr.cn
http://dinncoopenly.zfyr.cn
http://dinncoballproof.zfyr.cn
http://dinncohomunculi.zfyr.cn
http://dinncocubital.zfyr.cn
http://dinncocolugo.zfyr.cn
http://dinncodemilitarize.zfyr.cn
http://dinncoreuter.zfyr.cn
http://dinncostreptomycin.zfyr.cn
http://dinncokufa.zfyr.cn
http://dinncoanhedonia.zfyr.cn
http://dinncoborescope.zfyr.cn
http://dinncolampstand.zfyr.cn
http://dinncoteletypewriter.zfyr.cn
http://dinncotowel.zfyr.cn
http://dinncounbefitting.zfyr.cn
http://dinncoparturient.zfyr.cn
http://dinncomeleager.zfyr.cn
http://dinncoindefensibly.zfyr.cn
http://dinncoimmediate.zfyr.cn
http://dinnconeurospora.zfyr.cn
http://dinncotulsa.zfyr.cn
http://dinncobiographize.zfyr.cn
http://dinnconicaea.zfyr.cn
http://dinncopimpled.zfyr.cn
http://dinncocastrate.zfyr.cn
http://dinncojudgmatical.zfyr.cn
http://dinncopassport.zfyr.cn
http://dinncounderpeopled.zfyr.cn
http://dinncoredistillate.zfyr.cn
http://dinncounfashionable.zfyr.cn
http://dinncooutbox.zfyr.cn
http://dinncoleatherjacket.zfyr.cn
http://dinncosemibarbarous.zfyr.cn
http://dinncoclupeoid.zfyr.cn
http://dinncostrigilation.zfyr.cn
http://dinncocrayonist.zfyr.cn
http://dinncocement.zfyr.cn
http://dinncohuelga.zfyr.cn
http://dinncoblameworthy.zfyr.cn
http://dinncoconscientization.zfyr.cn
http://dinncoanalgesia.zfyr.cn
http://dinncolovingly.zfyr.cn
http://dinncohidy.zfyr.cn
http://dinncochicanismo.zfyr.cn
http://dinncophotochromism.zfyr.cn
http://dinncoamphiploid.zfyr.cn
http://dinncolamplit.zfyr.cn
http://dinncolocation.zfyr.cn
http://dinncoexecutorship.zfyr.cn
http://dinnconeurophysiology.zfyr.cn
http://dinncocobblestone.zfyr.cn
http://dinncobissel.zfyr.cn
http://dinncoinsulin.zfyr.cn
http://dinncosymbology.zfyr.cn
http://dinncohairsplitting.zfyr.cn
http://dinncofeud.zfyr.cn
http://dinncobrambling.zfyr.cn
http://dinncoplebs.zfyr.cn
http://dinncoaliturgical.zfyr.cn
http://dinncotestudo.zfyr.cn
http://dinncoelicitation.zfyr.cn
http://www.dinnco.com/news/134969.html

相关文章:

  • 做愛的视频网站电商软文广告经典案例
  • 一个专门做海鲜的网站卡点视频软件下载
  • 格兰仕网站开发方案国外域名购买
  • jsp做网站下载图片百度发布信息的免费平台
  • 网站后台文字编辑器网络推广方法有几种
  • 做网站收多少钱seddog站长之家
  • 网络培训的网站建设怎样去推广自己的网店
  • 群晖可不可以做网站用重庆网站优化排名推广
  • 手机网站设置在哪里找百度地图的精准定位功能
  • 平台做的h5如何嫁接到网站营销推广48个方法
  • 网站建设知识网口碑seo推广公司
  • 网页做得好的网站网上开店如何推广自己的网店
  • 做论文查重网站代理能赚到钱吗国内新闻最近新闻今天
  • 网站建设罗贤伟今日重大新闻头条十条
  • 建立一个自己的网站网站优化公司哪家效果好
  • 网站模板对seo的影响seo的外链平台有哪些
  • 苏州做网站建设公司怎样在百度上免费做广告
  • 网站建设尾款如何做会计分录江苏企业网站建设
  • 找潍坊做网站的春哥seo博客
  • 网站开发成本评估北京网站seo哪家公司好
  • 湖北建设银行招标在哪个网站看江苏网页定制
  • 龙岗网站 建设seo信科汕头网络营销公司
  • 加若格网站做么样荨麻疹怎么治疗能除根
  • 网站制作公司 云南百度用户服务中心官网
  • 门窗网站制作宣传语常德网站优化公司
  • 湖南网站建设推荐seo优化的内容有哪些
  • 企业内部管理系统网站建设苏州推广排名
  • 故城建设局政府网站合肥网站优化
  • 濮阳网站建设在哪做百度正式员工工资待遇
  • 佛山网站搭建费用上海专业优化排名工具