, reflectOb
will refer to an object of type MyClass
. The program
then executes methods on that instance.
One important point needs to be made. In this example, for the sake of simplicity, it
was assumed that the only two-argument constructor was one that took two int
arguments.
Obviously, in real-world code this would need to be verified by checking the parameter
type of each argument.
In the preceding example, everything about
has been discovered using reflection
except for one item: the type MyClass
, itself. That is, although the preceding examples
dynamically determined information about MyClass
, they still relied upon the fact that the
www.freepdf-books.com
P a r t I :
type name
was known in advance and used in a