mirror of
https://github.com/sjsdfg/effective-java-3rd-chinese.git
synced 2025-03-14 19:30:34 +08:00
update
This commit is contained in:
parent
b882b056e4
commit
5ef7049303
File diff suppressed because it is too large
Load Diff
@ -57,8 +57,8 @@ public static Boolean valueOf(boolean b) {
|
||||
- valueOf —— from 和 to 更为详细的替代 方式,例如:**BigInteger prime = BigInteger.valueOf(Integer.MAX_VALUE)**;
|
||||
- instance 或 getinstance —— 返回一个由其参数 (如果有的话) 描述的实例,但不能说它具有相同的值,例如:**StackWalker luke = StackWalker.getInstance(options)**;
|
||||
- create 或 newInstance —— 与 instance 或 getInstance 类似,除此之外该方法保证每次调用返回一个新的实例,例如:**Object newArray = Array.newInstance(classObject, arrayLen)**;
|
||||
- getType —— 与 getInstance 类似,**getType**中的**Type** 是工厂方法返回的对象类型,例如:**FileStore fs = Files.getFileStore(path)**;
|
||||
- newType —— 与 newInstance 类似,**newType**中的**Type** 是工厂方法返回的对象类型,例如:**BufferedReader br = Files.newBufferedReader(path)**;
|
||||
- getType —— 与 getInstance 类似,但是在工厂方法处于不同的类中的时候使用。**getType** 中的 **Type** 是工厂方法返回的对象类型,例如:**FileStore fs = Files.getFileStore(path)**;
|
||||
- newType —— 与 newInstance 类似,但是在工厂方法处于不同的类中的时候使用。**newType**中的 **Type** 是工厂方法返回的对象类型,例如:**BufferedReader br = Files.newBufferedReader(path)**;
|
||||
- type —— getType 和 newType 简洁的替代方式,例如:**List\<Complaint\> litany = Collections.list(legacyLitany)**;
|
||||
|
||||
总之,静态工厂方法和公共构造方法都有它们的用途,并且了解它们的相对优点是值得的。通常,静态工厂更可取,因此避免在没有考虑静态工厂的情况下直接选择使用公共构造方法。
|
||||
|
Loading…
Reference in New Issue
Block a user