Java7 编程语言特性
来源:互联网 发布:html windows.onload 编辑:程序博客网 时间:2024/05/16 17:28
jdk语言新特性:
1. 二进制表达方式:
/* jdk1.6*/byte b = (byte) 2 ;short aShort = (short) 2 ;int anInt2 = 2;long aLong = 2;/*jdk1.7*/byte b = (byte)0b10 ;short aShort = (short) 0b10 ;int anInt2 = 0b10 ;long aLong = 0b10L;2.新增使用下划线对数字进行分隔表达:
/*jdk1.6*/long a = 999999999999L ;int i = 1111111111111111;/*jdk1.7*/long a = 999_999_999_999L ;int i = 111_111111_1_111_111;/**不允许的语法*/float f1 = 3_.12f ;int i1 = 52_ ;int i2 = _51 ;double d1 = 3.12_ ;
3:switch 语句支持字符串变量:
/*jdk1.6*/switch( int | byte | char ){case int | byte | char : break ;default : // 代码break ; }/***jdk1.7*/switch( int | char | byte | String){case int | char | byte | String : break ;default : break ;}
4.泛型实例创建的类型推断
/**jdk1.6*/List<String>list = new ArrayList<String>() ;/**jdk 1.7*/List<String>list = new ArrayList<>() ;
5.同时捕获多个异常处理
/**jdk1.6*/try{System.out.println( "---" ) ;}catch(ArrayStoreException e){System.out.println( "异常---" ) ;}catch(ArithmeticException e2){System.out.println( "异常---" ) ;}/**jdk 1.7*/try{System.out.println( "---" ) ;}catch(ArrayStoreException|ArithmeticException e){System.out.println( "异常---" ) ;}
6. 使用可变参数时,提升编译器的警告和错误信息:
List l = new ArrayList<Number>();List<String> ls = l; // 警告信息l.add(0, new Integer(42)); //警告信息String s = ls.get(0); // 抛出类转换异常
- Java7 编程语言特性
- java7 实用的新特性:编程技巧
- Java7特性
- java7.的新特性!
- Java7新特性
- java7 新特性
- java7 新特性
- Java7新特性
- java7 新特性
- java7新特性(1)
- java7新特性
- JAVA7新特性
- Java7语法新特性
- java7 语法新特性
- Java7新特性
- java7 新特性
- java7的新特性
- Java7语法新特性:
- Db2 文件导入导出常见命令总结
- ffplay代码学习之thread线程
- include与jsp:include区别
- 统一编址与独立编址、I/O端口与I/O内存
- CString 的写时复制技术?
- Java7 编程语言特性
- myeclipse10.0优化及SVN安装配置
- 前微软高管推Mobilize.net 将老的.NET应用搬上云端和移动设备
- 如何安装字体
- XtraBackup
- Android 创建与解析XML(一)—— 概述
- VC++6.0与VS2010的区别
- Tomcat下为每个Web应用配置不同的访问端口
- Vi编辑器介绍