栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA优化(8)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA优化(8)

1.枚举项的数量建议不要超过64位

因为枚举数量小于等于64和大于64 利用EnumSet.noneOf产生的类不同,源码如下:

public static > EnumSet noneOf(Class elementType) {
 Enum[] universe = getUniverse(elementType);
 if (universe == null)
     throw new ClassCastException(elementType + " not an enum");

 if (universe.length <= 64)
     return new RegularEnumSet<>(elementType, universe);
 else
     return new JumboEnumSet<>(elementType, universe);
    }

RegularEnumSet是数字类型的操作,JumboEnumSet是数组操作

RegularEnumSet(ClasselementType, Enum[] universe) {
 super(elementType, universe);
    }
EnumSet(ClasselementType, Enum[] universe) {
 this.elementType = elementType;
 this.universe    = universe;
    }

JumboEnumSet(ClasselementType, Enum[] universe) {
 super(elementType, universe);
 elements = new long[(universe.length + 63) >>> 6];
    }
2.JAVA的泛型编译类型擦除的

所以一下代码会报错

  public void listMethon(List arrString) {

    }
    public void listMethon(List arrString) {

    }
List stringList = new ArrayList();
List integerList = new ArrayList();
System.out.println("是否相等"+(stringList.getClass() == integerList.getClass()));

打印结果:是否相等true

instanceof不允许存在泛型参数

System.out.println(stringList instanceof List);
这句会编译报错
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/238689.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号