File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Game Development and the fly likes accessing methods of another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "accessing methods of another class" Watch "accessing methods of another class" New topic

accessing methods of another class

kourosh parsa
Ranch Hand

Joined: Jan 22, 2012
Posts: 35
Hi. Here is the general structure if my code:

The problem is that my constructor needs the parameter "Board" which is the handle to the other class, but I cannot pass the parameter in claz.newInstance()
You see that I want to load classes dynamically where the class name is known at run time.
Any ideas what to do about this?
kourosh parsa
Ranch Hand

Joined: Jan 22, 2012
Posts: 35
well, I figured out that I can use
Element elm = (Element) claz.getDeclaredConstructor(Board.class).newInstance(this);
instead of
Element elm = (Element) claz.newInstance();

which works fine, but still if anyone has a better proposal, please let share it. Thanks
It is sorta covered in the JavaRanch Style Guide.
subject: accessing methods of another class
Similar Threads
Doubt about sub-super class relationship
Static variables and inheritance
Graphics problems
This and Constructor
Something about anonymous classes and variables