• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

create a new HashMap from a HashMap entries of other methods

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to make a new HashMap from the HashMap entries of the methods. Need to add the entries of a HashMap inside the methods to make a new HashMap.



Can anyone please suggest any way to do that. Thanks
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

I guess you could use reflection. I'd make sure this is what you *really* need to do.
 
ak swie
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.. Could you please help me with reflections. Is it thread safe? How do we implement the same.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pandeyalok kumar wrote:Can anyone please suggest any way to do that.



Why don't you just do this?


 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why don't you just do this?


Looks like he wants to call only the methods whose name is stored in a map.
 
Ulrika Tingle
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:

Why don't you just do this?


Looks like he wants to call only the methods whose name is stored in a map.



You never know until they tell you.
 
ak swie
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulrika Tingle wrote:

Christophe Verré wrote:

Why don't you just do this?


Looks like he wants to call only the methods whose name is stored in a map.



You never know until they tell you.




I have tried to generalise the actual code here that I am working on.
Will try to post a working code. But please consider this.



totalApplicableMethods gets its value from some predefined condition.
Here in the loop lets say I am calling method1(), method3(). So only they are invoked.
> I want 1=a and 3=c to be in my new HashMap hashTest1.
The loop is working correct. But I am getting hashTest1 empty {} in the end.>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

getMethod("method",param)


Here, you are trying to call a method called "method", which does not exist. I don't know where your try/catch are, but you should check that you're not getting an invocation exception (checked exception).
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, how can you call method.invoke(this, args); from a static method ? It's difficult to help without seeing some working code.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic