Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

accessing methods of another class

 
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
He does not suffer fools gladly. But this tiny ad does:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic