- Dont' use raw type in new code
- Eliminate unchecked warnings- Always use the Suppress-Warnings annotation on the smallest scope possible
- Prefer lists to ararys
- Arrays check type at runtime, generics check type at compile time
- type reified / type erasure
- can't create generic type array => type not safe because of type erasure
- type erasure: 不能直接 new E[], new List[], new List [] (non-reifiable type)
因為runtime沒辦法保證Array裡面存在一致的物件 - Favor Generic Type
- 盡量使用Generic Type,而不要讓Client端自己cast - Favor Generic Method
- type inference
- for static factory method
- recursive type bound - Use bounded wildcards to increase API flexibility
- PECS
- 如果Signature中只有一個type parameter, 就用wildcard - Consider typesafe heterogeneous containers
Help:
Class.asSubClass
Class.cast


0 意見:
張貼留言