[Core Java. Volume I. Fundamentals, 8th Edition]-11
来源:互联网 发布:移动网络改成电信 编辑:程序博客网 时间:2024/05/17 09:36
关于方法头异常的抛出
As with Java methods that are part of the supplied classes, you declare that your method may throw an exception with an exception specificationin the method header.
class MyAnimation { . . . public Image loadImage(String s) throws IOException { . . . } }
If a method might throw more than one checked exception type, you must list all exception classes in the header. Separate them by a comma as in the following example:
class MyAnimation { . . . public Image loadImage(String s) throws EOFException, MalformedURLException { . . . } }
子类方法不能比父类抛出更多异常
If you override a method from a superclass, the checked exceptions that the subclass method declares cannot be more general than those of the superclass method. (It is ok to throw more specific exceptions, or not to throw any exceptions in the subclass method.)
关于assert
The sole purpose of the expression part is to produce a message string. The AssertionError object does not store the actual expression value, so you can’t query it later. As the JDK documentation states with paternalistic charm, doing so “would encourage programmers to attempt to recover from assertion failure, which defeats the purpose of the facility.”
To assert that x is nonnegative, you can simply use the statement
assert x >= 0;
Or you can pass the actual value of x into the AssertionError object, so that it gets displayed later.
assert x >= 0 : x;
By default, assertions are disabled. You enable them by running the program with the -enableassertions or-ea option:
java -enableassertions MyApp
You can also disable assertions in certain classes and packages with the-disableassertions or-da option:
java -ea:... -da:MyClass MyApp
Some classes are not loaded by a class loader but directly by the virtual machine. You can use these switches to selectively enable or disable assertions in those classes. However, the -ea and -da switches that enable or disable all assertions do not apply to the “system classes” without class loaders. Use the-enablesystemassertions/-esa switch to enable assertions in system classes.
何时使用assert
* Assertion failures are intended to be fatal, unrecoverable errors.
* Assertion checks are turned on only during development and testing. (This is some times jokingly described as “wearing a life jacket when you are close to shore, and throwing it overboard once you are in the middle of the ocean.”)
logging
Logger.global.info("File->Open menu item selected");By default, the record is printed like this:
May 10, 2004 10:12:15 PM LoggingImageViewer fileOpen
INFO: File->Open menu item selected
禁用日志:
Logger.global.setLevel(Level.OFF);
多于一个模板类型的表示方法
A generic class can have more than one type variable.
public class Pair<T, U> { . . . }
加上类型限定的表示
<T extends BoundingType>expresses that T should be a subtype of the bounding type. Both T and the bounding type can be either a class or an interface.
A type variable or wildcard can have multiple bounds. For example:
T extends Comparable & Serializable
- [Core Java. Volume I. Fundamentals, 8th Edition]-11
- [Core Java. Volume I. Fundamentals, 8th Edition]-7,8
- Core Java(TM), Volume I--Fundamentals (8th Edition)
- [Core Java. Volume I. Fundamentals, 8th Edition]-2,3
- [Core Java. Volume I. Fundamentals, 8th Edition]-3
- [Core Java. Volume I. Fundamentals, 8th Edition]-4
- [Core Java. Volume I. Fundamentals, 8th Edition]-5
- [Core Java. Volume I. Fundamentals, 8th Edition]-6
- <Core Java Volume I Fundamentals 9th Edition> Note 01
- Core Java. Volume I. Fundamentals, 8th Edition 下载地址及读后感
- Core Java Volume I--Fundamentals, 10th Edition.pdf 英文原版 免费下载
- Core Java 2, Volume I:Fundamentals, Seventh Edition
- Core Java Volume I - Fundamentals (10th) 1-8章 阅读笔记
- Core.Java.Volume.I,2 10th.Edition
- Core Java, Volume II--Advanced Features (10th Edition) (Core Series) 电子书(手机)
- Core Java Volume I 读书笔记
- Core.Java.Volume.Fundamentals 阅读笔记(1)
- Core Java, Vol. 2: Advanced Features, 8th Edition
- Android 设置Activity的进入和退出效果
- Java 获得 CMD 输出信息
- 2013Esri全球用户大会Q&A之开发工具(web、桌面)
- 用dwr框架实现Web端服务器推送
- ajax请求类库
- [Core Java. Volume I. Fundamentals, 8th Edition]-11
- android 9patch使用
- Linux文件、文件夹权限的简述
- HTML之Table简约时尚CSS样式 + HTML中checkbox元素【全选】或【取消全选】、或得到选中个数全案例使用详解
- JDBC实现分页查询,同时使用动态数据源
- [基础]RHEL挂载ISO磁盘
- Java中堆内存和栈内存详解
- iptables开启与关闭
- android logo:内核、android开机动画