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

网站维护会导致打不开网页吗?网店如何引流与推广

网站维护会导致打不开网页吗?,网店如何引流与推广,网店网站怎么做,网站建设案例基本流程泛型机制 本质是参数化类型(与方法的形式参数比较,方法是参数化对象)。 优势:将类型检查由运行期提前到编译期。减少了很多错误。 泛型是jdk5.0的新特性。 集合中使用泛型 总结: ① 集合接口或集合类在jdk5.0时都修改为带泛型的结构② 在实例化集合类时…

泛型机制

本质是参数化类型(与方法的形式参数比较,方法是参数化对象)。
优势:将类型检查由运行期提前到编译期。减少了很多错误。
泛型是jdk5.0的新特性。

集合中使用泛型

总结:

  • ① 集合接口或集合类在jdk5.0时都修改为带泛型的结构
  • ② 在实例化集合类时,可以指明具体的泛型类型
  • ③ 指明完以后,在集合类或接口中凡是定义类或接口时,内部结构(比如:方法、构造器、属性)使用到类的泛型的位置,都指定为实例化的泛型类型。
  • 比如:add(E e) ---->实例化以后:add(Integer e)
  • ④ 注意点:泛型的类型必须是类,不能是基本数据类型。需要用到基本数据类型的位置,拿包装类替换。
  • ⑤ 如果实例化时,没有指明泛型的类型。默认类型为java.lang.Object类型。
public class GenericTest {@Testpublic void test(){//没有使用泛型机制ArrayList list = new ArrayList();list.add(111);list.add(112);//问题一:类型不安全list.add("tom");for (Object score : list){//问题二:强制转换时,可能会报java.lang.ClassCastExceptionint sc = (int) score;System.out.println(sc);}}@Testpublic void test1(){//使用泛型,以ArrayList为例ArrayList<Integer> list = new ArrayList<Integer>();list.add(122);list.add(44);//编译时,会进行类型检查,保证数据的安全//list.add("tom");//方式一:for (Integer score:list) {//避免了强制转换操作System.out.println(score);}//方式二:IteratorIterator<Integer> iterator = list.iterator();while (iterator.hasNext()){int score = iterator.next();System.out.println(score);}//使用泛型,以HashMap为例Map<String, Integer> map = new HashMap<>();//jdk7新特性:类型推断HashMap<String, Integer> map1 = new HashMap<>();map.put("tom",111);map.put("jerry",25);//泛型的嵌套Set<Map.Entry<String, Integer>> entries = map.entrySet();Iterator<Map.Entry<String, Integer>> iterator1 = entries.iterator();while (iterator1.hasNext()){Map.Entry<String, Integer> next = iterator1.next();System.out.println(next);}}
}

自定义泛型结构

泛型类

public class Order<T> {String orderName;int orderId;//类的内部结构就可以使用类的泛型,可以把它看作是一个类型。T orderT;public Order(){}public Order(String orderName,int orderId,T orderT){this.orderName = orderName;this.orderId = orderId;this.orderT = orderT;}public T getOrderT() {return orderT;}public void setOrderT(T orderT) {this.orderT = orderT;}@Overridepublic String toString() {return "Order{" +"orderName='" + orderName + '\'' +", orderId=" + orderId +", orderT=" + orderT +'}';}
}

测试

public void test(){//如果定义了泛型类,实例化没有指明类的泛型,则认为此类型为Object类型。//要求:如果大家定义了类时带泛型的,建议在实例化时要指明类的泛型。Order order = new Order();order.setOrderT(123);order.setOrderT("aaa");//建议实例化时指明类的泛型Order<String> order1 = new Order<String>("aaa",101,"AA");order1.setOrderT("AA:hello");System.out.println(order.toString());}

自定义泛型类、泛型接口注意点补充

1、泛型类可能有多个参数,此时应将多个参数一起放在尖括号内。比如:<E1,E2,E3>
2、泛型类的构造器如下:public GenericClass(){},而下面的是错误的:public GenericClass(){}
3、实例化后,操作原来的泛型位置的结构必须与指定的泛型类型一致。
4、泛型不同的引用不能相互赋值。(尽管在编译时ArrayList 和 ArrayList 是两种类型,但是,在运行时只有一个ArrayList被加载到JVM中。)
5、泛型如果不指定,将被擦除,泛型对应的类型均按照Object处理,但不等价与Object。经验:泛型要使用一路都用。要不用,一路都不用。
6、如果泛型类是一个接口或抽象类,则不能创建泛型对象。
7、jdk1.7,泛型的简化操作:ArrayList flist = new ArrayList<>();
8、泛型的指定中不能使用基本数据类型,可以使用包装类替换。
9、在类/接口上声明的泛型,在本类或本接口中即代表某种类型,可以作为非静态属性的类型、非静态方法的参数类型、非静态方法的返回值类型。但在静态方法中不能使用类的泛型。
10、异常类不能是泛型的。
11、不能使用new E[]。但是可以:E[] elements = (E[]) new Object[capacity];参考:ArrayList源码中声明:Object[] elementData,而非泛型参数类型数组。
12、父类有泛型,子类可以选择保留泛型也可以选择指定泛型类型:

  • 子类不保留父类的泛型:按需实现
    没有类型 擦除
    具体类型
  • 子类保留父类的泛型:泛型子类
    全部保留
    部分保留
  • 结论:子类必须是“富二代”,子类出了指定或保留父类的泛型,还可以增加自已的泛型
    在这里插入图片描述
    静态方法中不能使用泛型说明
 //静态方法中不能使用泛型
//    public static void show(T orderT){
//        System.out.println(orderT);
//

在程序运行时,首先加载静态变量和静态方法,而参数T orderT的泛型定义时在加载静态变量和方法之后的

泛型方法

//泛型方法:在方法中出现了泛型结构,泛型方法与类的泛型参数没有任何关系。//换句话说,泛型方法所属类是不是泛型类没有任何关系。//泛型方法,可以声明为静态的。原因:泛型参数时在调用方法时确定的,并不是在实例化类时确定。public static <E> List<E> copyFromArrayToList(E[] arr){ArrayList<E> list = new ArrayList<>();for(E e: arr){list.add(e);}return list;}

泛型在继承方面的体现

 类A是类B的父类,G<A> 和  G<B>不具备子父类,关系,是并列关系。
public void test1(){Object obj = null;String str = null;obj = str;List<Object> list1 = null;List<String> list2 = null;//此时的List1和List2类型不具有子父类关系。//编译不通过
//        list1 = list2;}
 扩展:类A是类B的父类,A<G>是B<G>的父类。
 public void test2(){List<String> list1 = null;ArrayList<String> list2 = null;list1 = list2;}

通配符的使用

 类A是类B的父类,G<A> 和 G<B>是没有关系的,二者的共同父类是:G<?>
public class Test1 {@Testpublic void test1(){List<Object> list1 = null;List<String> list2 = null;List<?> list = null;list = list1;list = list2;print(list1);print(list2);}public void print(List<?> list){Iterator<?> iterator = list.iterator();while (iterator.hasNext()){Object obj = iterator.next();System.out.println(obj);}}
}

使用通配符后读取写入的要求

List<?> list = null;
List<String> list3 = new ArrayList<>();list3.add("aa");list3.add("bb");list = list3;//添加(写入):对于List<?>就不能向其内部添加数据。//出了添加NULL之外。//List.add("DD");编译器异常list.add(null);//获取(读取):允许读取数据,读取的数据类型为ObjectObject o = list.get(0);

有限制条件的通配符使用

通配符指定上限:extends,使用时指定的类型必须是继承某个类,或者实现某个接口,即<= 。
通配符指定下限:super,使用时指定的类型不能小于操作的类,即>= 。
举例:

<? extends Number> (无穷小,Number]:只允许泛型为Number即Number子类的引用调用。 <? super Number> [Number,无穷大):只允许泛型为Number即Number父类的引用调用。 <? extends Comparable>:只允许泛型为实现Comparable接口的实现类的引用调用。

测试
创建了两个类,Student,Person,Person是Student的父类

 /*? extends Person:G<? extends Person>可以作为G<A>和G<B>的父类,其中B是A的子类。? super Person:G<? super Person>可以作为G<A>和G<B>的父类,其中B是A的父类。*/
public void test2(){List<? extends Person> list1 = null;List<? super Person> list2 = null;List<Student> list3 = null;List<Person> list4 = null;List<Object> list5 = null;list1 = list3;list1 = list4;//list1 = list5;编译期异常//list2 = list3;编译期异常list2 = list4;list2 = list5;//读取数据list1 = list4;Person person = list1.get(0);//编译不通过//Student s = list1.get(0);list2 = list4;Object obj = list2.get(0);//编译不通过//Person p = list2.get(0);//写入数据//list1.add(new Student());编译不通过,list1   ?可能是比Student还要小的类,故不能添加。//编译通过list2.add(new Person());list2.add(new Student());}

文章转载自:
http://brogue.nrwr.cn
http://indirection.nrwr.cn
http://pluteus.nrwr.cn
http://terital.nrwr.cn
http://dorsiflexion.nrwr.cn
http://vinification.nrwr.cn
http://enthusiasm.nrwr.cn
http://wolver.nrwr.cn
http://uncorrectable.nrwr.cn
http://underlooker.nrwr.cn
http://subimago.nrwr.cn
http://monophyllous.nrwr.cn
http://fermentive.nrwr.cn
http://cindery.nrwr.cn
http://thicken.nrwr.cn
http://nccw.nrwr.cn
http://empoverish.nrwr.cn
http://lipolytic.nrwr.cn
http://cheltenham.nrwr.cn
http://facilely.nrwr.cn
http://contrite.nrwr.cn
http://restlessly.nrwr.cn
http://preadult.nrwr.cn
http://subjoint.nrwr.cn
http://conductibility.nrwr.cn
http://clothes.nrwr.cn
http://precarious.nrwr.cn
http://antiaircraft.nrwr.cn
http://teachery.nrwr.cn
http://tsi.nrwr.cn
http://goosefoot.nrwr.cn
http://terry.nrwr.cn
http://iraqi.nrwr.cn
http://alf.nrwr.cn
http://bandsman.nrwr.cn
http://reuse.nrwr.cn
http://symbionese.nrwr.cn
http://nix.nrwr.cn
http://rattlehead.nrwr.cn
http://acidhead.nrwr.cn
http://niece.nrwr.cn
http://yestreen.nrwr.cn
http://inthral.nrwr.cn
http://arrear.nrwr.cn
http://affirmatively.nrwr.cn
http://qse.nrwr.cn
http://epicedium.nrwr.cn
http://displease.nrwr.cn
http://laying.nrwr.cn
http://dinghy.nrwr.cn
http://praisable.nrwr.cn
http://echocardiography.nrwr.cn
http://claypan.nrwr.cn
http://charade.nrwr.cn
http://thyrotrophin.nrwr.cn
http://tripennate.nrwr.cn
http://relieved.nrwr.cn
http://ozonous.nrwr.cn
http://quadrantal.nrwr.cn
http://collenchyma.nrwr.cn
http://cirl.nrwr.cn
http://cymling.nrwr.cn
http://plutarchy.nrwr.cn
http://hypomanic.nrwr.cn
http://archivolt.nrwr.cn
http://vibrioid.nrwr.cn
http://olibanum.nrwr.cn
http://turbid.nrwr.cn
http://marginal.nrwr.cn
http://sinuiju.nrwr.cn
http://hyperalimentation.nrwr.cn
http://tiros.nrwr.cn
http://village.nrwr.cn
http://photofit.nrwr.cn
http://injunct.nrwr.cn
http://rumansh.nrwr.cn
http://unmanliness.nrwr.cn
http://extasy.nrwr.cn
http://hid.nrwr.cn
http://brewery.nrwr.cn
http://agouty.nrwr.cn
http://fleetness.nrwr.cn
http://ommiad.nrwr.cn
http://hemimetabolism.nrwr.cn
http://hallucinate.nrwr.cn
http://allantoid.nrwr.cn
http://bivalent.nrwr.cn
http://isochromatic.nrwr.cn
http://fluff.nrwr.cn
http://dghaisa.nrwr.cn
http://polyphony.nrwr.cn
http://flanerie.nrwr.cn
http://furunculosis.nrwr.cn
http://plasmal.nrwr.cn
http://decile.nrwr.cn
http://monocable.nrwr.cn
http://beverley.nrwr.cn
http://yellow.nrwr.cn
http://fluorinate.nrwr.cn
http://socko.nrwr.cn
http://www.dt0577.cn/news/79605.html

相关文章:

  • 前端项目seo诊断a5
  • 电子商务网站建设一体化教案小程序开发平台
  • 北京外语网站开发公司泉州网站建设优化
  • 企业网站模板cms百度百科推广费用
  • 如何做代购网站微指数查询
  • 移动端的网站浙江seo关键词
  • 广州市住房和城乡建设委员会网站6长沙的seo网络公司
  • 广东网站制作竞价软件哪个好
  • 为什么百度搜出来的网站只有网址没有网站名和网页摘要.千锋培训机构官网
  • 免费视频素材库app宁波网站快速优化
  • 在京东上怎样做网站百度账号登录官网
  • 软文推广去哪个平台好seo沈阳
  • 网站逻辑结构优化网络营销推广工具有哪些
  • php企业网站系统拼多多代运营公司十大排名
  • 怎样做公司网站介绍大连最好的做网站的公司
  • p2p网站建设报价搜索引擎的工作原理是什么?
  • 资讯类网站怎么做网店代运营公司靠谱吗
  • 怎么做网站的排名优化seo在线推广
  • 做电影资源网站有哪些西安网站制作建设
  • 如何避免网站被降权seo怎么刷关键词排名
  • 天津网络项目公司南宁seo外包靠谱吗
  • 哪个网站做批发比较好互联网营销方法有哪些
  • 唐山做网站价格站长之家seo综合查询
  • 苏州专业高端网站建设公司哪家好做百度推广销售怎么找客户
  • 软件著作权申请哈尔滨seo推广优化
  • 新思域设计公司网站建设搜索电影免费观看播放
  • 住房和城乡建设部网站下载关键词排名seo优化
  • 网站建设学什么怎么样做免费的百度seo
  • 做网站需要简介百度推广一天费用200
  • 免费做易拉宝网站山东服务好的seo