Resources should be closed
资源未关闭,打开发现有两处用到的IO流没有关闭
Conditions should not unconditionallyevaluate to "TRUE" or to "FALSE"
if/else判断里出现了重复判断,比如在if(a>10)的执行体里面又判断if(a<0),而后者肯定不会是true
Exception handlers should preserve theoriginal exception
处理异常的时候应该保留原始的异常情况,不要直接来个catch(Exception e)了事
Throwable.printStackTrace(...) should notbe called
不应该直接调用e.printStackTrace(),而是用Loggers来处理(就是打Log)。
Loggers的优势是:Users are ableto easily retrieve the logs.
The format of log messages is uniform andallow users to browse the logs easily.
Instance methods should not write to"static" fields
不要用实例方法改变静态成员,理想情况下,静态变量只通过同步的静态方法来改变
"public static" fields should beconstant
公共静态成员应该加上final,也就是public static final 一般不分家
Thread.run() and Runnable.run() should notbe called directly
不应该直接调用Thread和Runnaale对象的run方法,直接调用run会使得run方法执行在当前线程,失去了开启新线程的意义。但有时候可能会这样做,下面有个例子。
Generic exceptions should never be thrown
不太理解,大意是说不要直接抛Error,RuntimeException/Throwable/Exception这样的通用的异常。我的具体应用是:throw new Error("Error copying database"),给出的建议是:Defineand throw a dedicated exception instead of using a generic one(定义并抛出一个专用的异常来代替一个通用的异常)
Class variable fields should not havepublic accessibility
类变量不要设置为public,而是设为private,再提供get和set方法。
Sections of code should not be"commented out"
不要再注释中出现大量的代码段,会使代码可读性变差
Package declaration should match sourcefile directory
这个没理解,包的声明应该与源文件目录匹配。
Utility classes should not have publicconstructors
工具类不应该有公共的构造器,也就是说至少要有一个private的构造器,如果没有,默认的构造器是public的。
The diamond operator ("<>")should be used
在定义集合的时候,等号右边的<>内不需要再写上元素类型,直接空着就行。
Lambdas and anonymous classes should nothave too many lines9
Lambdas表达式和匿名内部类不要写太多行,一般最多写20行。
Anonymous inner classes containing only onemethod should become lambdas
只包含一个方法的匿名内部类应该写成Lambdas表达式的形式,增强代码可读性
Try-with-resources should be used
用Try-with-resources的形式取代try/catch/finally的形式,这个有待于以后学习。