Java Reference
In-Depth Information
tion that had occurred (withdraw, deposit, and so on), and a long value,
representing the amount involved. If you use getdeclaredConstructors to
obtain that Constructor object and print its signature using toString , you
will get the following:
BankAccount$Action(BankAccount,java.lang.String,long)
Here you can see both the use of the $ naming convention for inner
classes and the implicitly added constructor argument that refers to the
enclosing object. You can retrieve this constructor as follows:
Class<Action> actionClass = Action.class;
Constructor<Action> con =
actionClass.getDeclaredConstructor(BankAccount.class,
String.class, long.class);
If you want to construct an Action object you must supply an appropriate
enclosing object reference as in
BankAccount acct = new BankAccount();
// ...
Action a = con.newInstance(acct, "Embezzle", 10000L);
 
Search WWH ::




Custom Search