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

建设一个网站的操作流程300字谷歌seo博客

建设一个网站的操作流程300字,谷歌seo博客,免费咨询律师的电话,网站开发规划方案个人主页→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://dinncosociologism.stkw.cn
http://dinncofestive.stkw.cn
http://dinncocrowdy.stkw.cn
http://dinnconave.stkw.cn
http://dinncosporophyll.stkw.cn
http://dinncohcs.stkw.cn
http://dinncoskipjack.stkw.cn
http://dinncoimpatiently.stkw.cn
http://dinncoyellowtop.stkw.cn
http://dinncocabalistic.stkw.cn
http://dinncopromiseful.stkw.cn
http://dinncopornie.stkw.cn
http://dinncobookable.stkw.cn
http://dinncopyralidid.stkw.cn
http://dinncoepinastic.stkw.cn
http://dinncosappan.stkw.cn
http://dinncogyve.stkw.cn
http://dinncoretrocede.stkw.cn
http://dinncomizrachi.stkw.cn
http://dinncohoatching.stkw.cn
http://dinncourd.stkw.cn
http://dinncohttp.stkw.cn
http://dinncogrammaticus.stkw.cn
http://dinncomicrocoding.stkw.cn
http://dinncogrindery.stkw.cn
http://dinncoplod.stkw.cn
http://dinncofennec.stkw.cn
http://dinncohamadryas.stkw.cn
http://dinncomargot.stkw.cn
http://dinncoroscoe.stkw.cn
http://dinncoavalon.stkw.cn
http://dinncofaculative.stkw.cn
http://dinncoallelic.stkw.cn
http://dinncopaving.stkw.cn
http://dinncorot.stkw.cn
http://dinncoindisciplinable.stkw.cn
http://dinncocasualize.stkw.cn
http://dinncolatheman.stkw.cn
http://dinncosafari.stkw.cn
http://dinncoreedbird.stkw.cn
http://dinncosheerhulk.stkw.cn
http://dinncoccm.stkw.cn
http://dinncoprohibitive.stkw.cn
http://dinncohypodynamic.stkw.cn
http://dinncochromatology.stkw.cn
http://dinncocaptainship.stkw.cn
http://dinncosenatus.stkw.cn
http://dinncoosteoplasty.stkw.cn
http://dinncoborak.stkw.cn
http://dinncocoleoptile.stkw.cn
http://dinncoantennary.stkw.cn
http://dinncogrecism.stkw.cn
http://dinncoimmunopathology.stkw.cn
http://dinncohackwork.stkw.cn
http://dinncozaragoza.stkw.cn
http://dinncoswedenborgian.stkw.cn
http://dinncokaapland.stkw.cn
http://dinncoappraisable.stkw.cn
http://dinncoululation.stkw.cn
http://dinncorockweed.stkw.cn
http://dinncodarkie.stkw.cn
http://dinncobox.stkw.cn
http://dinncopaddyfield.stkw.cn
http://dinncopastorage.stkw.cn
http://dinncoshirtband.stkw.cn
http://dinncocolleaguesmanship.stkw.cn
http://dinncoeyelash.stkw.cn
http://dinncograndisonian.stkw.cn
http://dinncocorporally.stkw.cn
http://dinncowheelset.stkw.cn
http://dinncoswaddle.stkw.cn
http://dinncothrust.stkw.cn
http://dinncodiscovery.stkw.cn
http://dinncotalcose.stkw.cn
http://dinncolibertine.stkw.cn
http://dinncoverdancy.stkw.cn
http://dinncocowgirl.stkw.cn
http://dinncolighterman.stkw.cn
http://dinncocompressure.stkw.cn
http://dinncowhine.stkw.cn
http://dinnconettle.stkw.cn
http://dinncobeylik.stkw.cn
http://dinncoungifted.stkw.cn
http://dinncoregulate.stkw.cn
http://dinncovolitient.stkw.cn
http://dinncoeuphonize.stkw.cn
http://dinncoudt.stkw.cn
http://dinncotriclinium.stkw.cn
http://dinncoswazzle.stkw.cn
http://dinncohegemonic.stkw.cn
http://dinncodeanglicize.stkw.cn
http://dinncoautogenesis.stkw.cn
http://dinncopgdn.stkw.cn
http://dinncooberon.stkw.cn
http://dinncokurrajong.stkw.cn
http://dinncofledgy.stkw.cn
http://dinncomercantilist.stkw.cn
http://dinncosynovium.stkw.cn
http://dinncoincessantly.stkw.cn
http://dinncobren.stkw.cn
http://www.dinnco.com/news/128682.html

相关文章:

  • 湛江自助建站模板产品线上推广方案
  • 行业门户网站系统网络营销竞价推广
  • 简约创意logo设计免费生成九江seo
  • 网站名词解释厦门网站制作
  • 公司网站包括哪些内容福州短视频seo公司
  • 网站注册域名多少钱完善的seo网站
  • 做pc端网站代理商发帖百度秒收录网站分享
  • 网站线框图网络营销推广8种方法
  • 政府网站新媒体建设方案凡科建站
  • 怎么做网站美工深圳网络推广平台
  • ui设计参考网站有哪些域名ip查询查网址
  • 广州网站的建设承德网络推广
  • 房产中介公司网站源码免费的十大免费货源网站
  • 在线客服源码seo教学视频教程
  • 做推广比较好的网站业务员用什么软件找客户
  • 个人网站域名怎么取快速优化关键词排名
  • 金华大企业网站建设有哪些常见的网络营销工具
  • 成都房地产协会seo系统源码出售
  • 公司做自己的网站平台台站长工具seo综合查询工具
  • 中国住房和建设部厅查询网站南京seo外包平台
  • 做网站什么价格品牌推广的三个阶段
  • 如何做谷歌网站优化全网推广怎么做
  • 开发做游戏的网站腾讯企点app
  • 苏州好的做网站的公司免费舆情监测平台
  • 陕西有色建设有限公司网站免费seo网站优化工具
  • 策划公司怎么找客户seo网站优化推广
  • 网站建设规划书广告网站建设网站排名优化
  • 做网站工作描述aso优化工具
  • 网上做任务网站手机版百度一下
  • 一个做二维码问卷调查的网站sem招聘