Java Reference
In-Depth Information
< Day Day Up >
13. Reflection
This section concerns Java's core reflection APIs.
13.1. Reflection checks access to the entity and to its class
Prescription:
Use reflection to instantiate classes; interfaces to access instances.
References:
Puzzle 78
; [EJ Item 35].
13.2. Reflectively instantiating an inner class requires an extra
argument
Prescription:
Don't use reflection on inner classes.
Prefer static member classes to inner classes.
References:
Puzzle 80
; [JLS 13.1] and [EJ Item 18].
13.3.
Class.newInstance
can throw undeclared checked exceptions
Prescription:
Use
java.lang.reflect.Constructor.newInstance
instead of
Class.newInstance
if there is any possibility of the constructor throwing a checked exception.
References:
Puzzle 43
.
< Day Day Up >
Search WWH ::
Custom Search