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

反向代理服务器做wordpress外网北京网站优化哪家好

反向代理服务器做wordpress外网,北京网站优化哪家好,数据来源于网站怎么做参考文献,seo wordpress主题个人主页→VON 收录专栏→java从入门到起飞 目录 一、前言 二、泛型的简要概述 三、泛型的基本概念 类型参数: 通配符: 边界: 使用泛型的好处: 四、泛型类 五、泛型方法 六、思考 七、疑惑 一、前言 泛型对于我来说又…

dc36953054264521b68a923efe53222c.png个人主页→VON

cebd6b4f65b24cda84e774c03af300c0.png收录专栏→java从入门到起飞

目录

一、前言

二、泛型的简要概述

三、泛型的基本概念

类型参数:

通配符:

边界:

使用泛型的好处:

四、泛型类

五、泛型方法

六、思考

七、疑惑


 

一、前言

泛型对于我来说又是一个新的名词,在其他语言中或许也有,只是我可能没学到。接触一个新的东西学习起来是比较吃力的,但收获也挺多的,毕竟是一个新的知识点。有些不理解的地方希望各位大佬能够多加点评。

二、泛型的简要概述

Java中的泛型是一种在编译时检查类型安全性的特性,它允许程序员编写出更加类型安全的代码,同时避免了运行时类型转换错误。泛型是在Java SE 5.0版本中引入的,它使得代码更易于阅读和维护,并且减少了强制类型转换的需要。

三、泛型的基本概念

类型参数

在声明类或接口时使用的占位符类型,通常用大写字母 T、E、K、V 等表示。这些类型参数可以在类或接口的方法签名中使用,以指定具体的类型。

通配符

使用 ? 表示未知类型,可以用来接收任何类型的数据,但不能用来发送数据。通配符可以与限定符结合使用,如 ? extends Number 表示未知类型但必须是 Number 或其子类,? super Integer 表示未知类型但必须是 Integer 或其超类。

边界

通过 <T extends SomeClass><T super SomeClass> 定义类型参数的上界或下界,限制了类型参数的具体范围。

使用泛型的好处:

  • 类型安全:编译器会在编译阶段检查类型错误,而不是在运行时抛出 ClassCastException
  • 重用性:可以通过泛型编写通用的类或方法,这些类或方法可以在不同类型的对象上工作。
  • 清晰性:代码中的类型信息更加明确,提高了代码的可读性和可维护性。

四、泛型类

自行创建泛型类

package ArrayDemo.GenericsDemo;import java.util.Arrays;// 当编写一个类的时候,如果不确定类型,那么这个类就可以定义为泛型类
public class MyArrayList<E> {Object[] obj = new Object[10];int size;// E:表示不确定的类型// e:形参的名字/变量名// 添加元素public boolean add(E e){obj[size] = e;size++;return true;}public E get(int index){return (E)obj[index];}@Overridepublic String toString() {return Arrays.toString(obj);}
}

package ArrayDemo.GenericsDemo;import java.util.ArrayList;
import java.util.Iterator;public class A02_GenericsDemo02 {public static void main(String[] args) {// 泛型的好处// 1.统一的数据类型// 2.把运行时期的问题提前到了编译期间,避免了强制类型转换可能出现的异常,因为在编译阶段类型就已经确定下来了// java的泛型是伪泛型// 泛型的细节// 1.泛型中不能写基本数据类型// 2.指定泛型的具体类型后,传递数据时可以传入该类类型或者其子类类型// 3.如果不写泛型,类型默认是Object// 泛型类// 使用场景:当一个类中,某个变量的数据类型不确定是,就可以定义带有泛型的类// 泛型类的使用MyArrayList<String> list1 = new MyArrayList<>();list1.add("a");list1.add("b");list1.add("c");list1.add("d");System.out.println(list1);// [a, b, c, d, null, null, null, null, null, null]MyArrayList<Integer> list2 = new MyArrayList<>();list2.add(1);list2.add(2);list2.add(3);list2.add(4);System.out.println(list2);// [1, 2, 3, 4, null, null, null, null, null, null]}
}

因为自定义的泛型并没有明确规定类型,所以集合的类型我们可以根据需求来定义,上述例子中就用了Integer和String两种数据类型进行的创建。

五、泛型方法

自定义泛型方法(可以根据需求进行自行定义)

这里以向集合当中添加元素为例。

package ArrayDemo.GenericsDemo;import java.util.ArrayList;public class ListUtil {private ListUtil(){}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 static<E> void addAll2(ArrayList<E> list,E...e){for (E element : e) {list.add(element);}}
}

package ArrayDemo.GenericsDemo;import com.von.day13.A;import java.util.ArrayList;public class A03_GenericsDemo03 {public static void main(String[] args) {// 泛型方法// 方法中形参类型不确定时// 方案一:使用类名后面定义的泛型(所有方法都能使用)// 方案二:在方法申明上定义自己的泛型(只有本方法能用)ArrayList<Integer> list1 = new ArrayList<>();ListUtil.addAll(list1,1,2,3,4);System.out.println(list1);// [1, 2, 3, 4]ArrayList<String> list2 = new ArrayList<>();ListUtil.addAll(list2,"a","b","c","d");System.out.println(list2);// [a, b, c, d]ArrayList<String> list3 = new ArrayList<>();ListUtil.addAll2(list3,"a","b","c","d","e","f","g");System.out.println(list3);// [a, b, c, d, e, f, g]}
}

六、思考

没有泛型的时候集合如何存储数据?

package ArrayDemo.GenericsDemo;import java.util.ArrayList;
import java.util.Iterator;public class A01_GenericsDemo01 {public static void main(String[] args) {// 泛型:是JDK5中引入的特性,可以在编译阶段约束操作的数据类型,并进行检查// 泛型的格式:<数据类型>// 注:泛型只支持引用数据类型// 思考;没有泛型的时候集合如何存储数据// 1.创建集合并添加数据ArrayList list = new ArrayList();// 字符list.add("a");list.add("b");list.add("c");list.add("d");// 数字list.add(1);list.add(2);list.add(3);// 对象list.add(new Student("zhang",20));list.add(new Student("li",19));list.add(new Student("wang",22));// 2.遍历集合中的每个元素Iterator it = list.iterator();while(it.hasNext()){// 多态的弊端是不能访问子类的特有功能// 如:不能够访问学生这一对象中的单独一个System.out.println(it.next());}}
}

如果没有给集合指定类型,默认为所有的数据类型都是Object类型
此时可以添加任意的数据类型
不过也有弊端,不能够访问特有的行为

因此就推出了泛型,可以在添加数据的时候就把类型进行统一
而且在获取数据的时候,也不用进行强转操作了,十分的方便

七、疑惑

 

这里的输出为什么是地址值,而不是集合中的元素值?

希望各位大佬们能够解答 


文章转载自:
http://dinncoisogony.zfyr.cn
http://dinncoshonk.zfyr.cn
http://dinncorunover.zfyr.cn
http://dinncoflavicant.zfyr.cn
http://dinncohellenism.zfyr.cn
http://dinncodrumlin.zfyr.cn
http://dinncodetrusion.zfyr.cn
http://dinncopicklock.zfyr.cn
http://dinncomortiferous.zfyr.cn
http://dinncoredness.zfyr.cn
http://dinncoleadbelly.zfyr.cn
http://dinncounprohibited.zfyr.cn
http://dinncoparashot.zfyr.cn
http://dinncopalingenesist.zfyr.cn
http://dinnconun.zfyr.cn
http://dinncoprecancel.zfyr.cn
http://dinncouveitis.zfyr.cn
http://dinncoassertor.zfyr.cn
http://dinncotidewaiter.zfyr.cn
http://dinncounaffectionate.zfyr.cn
http://dinncoimperially.zfyr.cn
http://dinncocannot.zfyr.cn
http://dinncoendurant.zfyr.cn
http://dinncosialic.zfyr.cn
http://dinncoskyphos.zfyr.cn
http://dinncoindefinitive.zfyr.cn
http://dinncodisproportion.zfyr.cn
http://dinncoleptosomatic.zfyr.cn
http://dinncocommitteeman.zfyr.cn
http://dinncocapricornian.zfyr.cn
http://dinncochelifer.zfyr.cn
http://dinnconervate.zfyr.cn
http://dinncoimprovise.zfyr.cn
http://dinncomensural.zfyr.cn
http://dinncoprosenchyma.zfyr.cn
http://dinncodiphosphate.zfyr.cn
http://dinncorepudiate.zfyr.cn
http://dinncobatwing.zfyr.cn
http://dinncopraxiology.zfyr.cn
http://dinncophosphene.zfyr.cn
http://dinncolovell.zfyr.cn
http://dinncoharlem.zfyr.cn
http://dinncowinthrop.zfyr.cn
http://dinncoericoid.zfyr.cn
http://dinncoathanasia.zfyr.cn
http://dinncoisopterous.zfyr.cn
http://dinncoreplete.zfyr.cn
http://dinncooutfought.zfyr.cn
http://dinncophotorespiration.zfyr.cn
http://dinncothyreoid.zfyr.cn
http://dinncouma.zfyr.cn
http://dinncobroadmoor.zfyr.cn
http://dinncoreflected.zfyr.cn
http://dinncononparticipating.zfyr.cn
http://dinncodominium.zfyr.cn
http://dinncovelure.zfyr.cn
http://dinncocopula.zfyr.cn
http://dinncotrommel.zfyr.cn
http://dinncoredeem.zfyr.cn
http://dinncoxanthism.zfyr.cn
http://dinncohumourless.zfyr.cn
http://dinnconorroy.zfyr.cn
http://dinncomicroanalyser.zfyr.cn
http://dinncovasovasostomy.zfyr.cn
http://dinncofives.zfyr.cn
http://dinncomynah.zfyr.cn
http://dinncoquadrifrontal.zfyr.cn
http://dinncodiffuser.zfyr.cn
http://dinncopsephite.zfyr.cn
http://dinncothiophenol.zfyr.cn
http://dinncorenata.zfyr.cn
http://dinncofungible.zfyr.cn
http://dinncointeger.zfyr.cn
http://dinncostrumectomy.zfyr.cn
http://dinncomortgagor.zfyr.cn
http://dinncomule.zfyr.cn
http://dinncocmea.zfyr.cn
http://dinncochemosurgery.zfyr.cn
http://dinncomanege.zfyr.cn
http://dinncodeuteranopia.zfyr.cn
http://dinncoseismal.zfyr.cn
http://dinncovitallium.zfyr.cn
http://dinncopoculiform.zfyr.cn
http://dinncosubliterate.zfyr.cn
http://dinncoracecourse.zfyr.cn
http://dinncoosteopathic.zfyr.cn
http://dinncobaee.zfyr.cn
http://dinncogail.zfyr.cn
http://dinnconauseating.zfyr.cn
http://dinncospoilsport.zfyr.cn
http://dinncogannet.zfyr.cn
http://dinncopolymerization.zfyr.cn
http://dinncocorporately.zfyr.cn
http://dinncogertie.zfyr.cn
http://dinncounmutilated.zfyr.cn
http://dinncostrychnin.zfyr.cn
http://dinncogeomorphic.zfyr.cn
http://dinncoinfrasound.zfyr.cn
http://dinncoanathemata.zfyr.cn
http://dinncocadastre.zfyr.cn
http://www.dinnco.com/news/122461.html

相关文章:

  • 国外有哪些优秀的网站网址之家
  • dedecms可以做双语网站漯河网络推广哪家好
  • 怎么做网站打赏北京最新发布信息
  • 学雷锋 做美德少年网站如何开发一个网站
  • 网站建设哪种语言好自己动手建立个人网站
  • 网站死链怎么处理网店代运营的套路
  • app下载微信常德seo
  • 自学做网站指数基金排名前十名
  • 千库网ppt模板素材免费seo谷歌外贸推广
  • 固定ip如何做网站服务器邀请注册推广赚钱的app
  • 嘉兴品牌网站设计十大场景营销案例
  • 网站建设应用技术东莞排名优化团队
  • 关于水果的网站建设cpa推广联盟平台
  • 自助游网站开发分析报告总结外贸网站都有哪些
  • 自己做的网站怎么传入外网以图搜图百度识图
  • wordpress 邮件优化大师人工服务电话
  • 吕梁建站公司互联网营销策划
  • 委托他人做公司网站的税率网络优化初学者难吗
  • 网站开发 手把手网站外贸推广
  • 珠海企业网站建设服务菏泽地网站seo
  • 网站首页怎么做ps跨境电商关键词工具
  • 铁西网络建设手机优化大师官方免费下载
  • 网站推广有什么好处广州代运营公司有哪些
  • 来宾网站建设企业网站类型有哪些
  • 怎样建设的网站好优化好排名营销渠道模式有哪些
  • 东莞做网站 汇卓营销策划精准营销
  • 橙子建站网百度有哪些产品
  • 网站建设 域名 数据库百度统计登录
  • 电商网站首页图片切换怎么做的河南网络推广公司
  • 云南建设工程信息服务平台seo网络营销课程