This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes create a new HashMap from a HashMap entries of other methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "create a new HashMap from a HashMap entries of other methods" Watch "create a new HashMap from a HashMap entries of other methods" New topic
Author

create a new HashMap from a HashMap entries of other methods

ak swie
Greenhorn

Joined: Dec 08, 2009
Posts: 9
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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 08, 2009
Posts: 9
Thanks.. Could you please help me with reflections. Is it thread safe? How do we implement the same.
Ulrika Tingle
Ranch Hand

Joined: Nov 24, 2009
Posts: 92
pandeyalok kumar wrote:Can anyone please suggest any way to do that.


Why don't you just do this?


Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Why don't you just do this?

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


[My Blog]
All roads lead to JavaRanch
Ulrika Tingle
Ranch Hand

Joined: Nov 24, 2009
Posts: 92
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

Joined: Dec 08, 2009
Posts: 9
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

Also, how can you call method.invoke(this, args); from a static method ? It's difficult to help without seeing some working code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: create a new HashMap from a HashMap entries of other methods