I came across an example of @Autowired
:
public class EmpManager {
@Autowired
private EmpDao empDao;
}
I was curious about how the empDao
get sets since there are no setter methods and it is private.
Java allows access controls on a field or method to be turned off (yes, there's a security check to pass first) via the AccessibleObject.setAccessible()
method which is part of the reflection framework (both Field
and Method
inherit from AccessibleObject
). Once the field can be discovered and written to, it's pretty trivial to do the rest of it; merely a Simple Matter Of Programming.