× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Pete,

According to the JavaDocs for java.util.HashMap, the 'put' method is supposed to return the object that was previously assigned to the key, or else it should return null if no object was previously assigned to the key.

I'm looking at these Javadocs:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

Since you just created the hashmap *immediately* before calling the 'put' method, I think it's safe to assume that there's nothing assigned to any of the keys in the hashmap -- that being the case, 'null' is the *expected* return value.

So I guess I don't understand what the issue is?

Your message implies that the Java code doesn't do the same thing -- but the Java code that you demonstrated doesn't even attempt to check the return value!

Obviously, there's additional code in your application that I haven't seen, so maybe I'm missing the point. Can you show the code that's returning a null when it shouldn't be?


Pete Helgren wrote:
I have been puzzling over how to wrap the HashMap put method. I successfully (I thought) built prototypes, interfaces and an RPG wrapper to handle the call, but I must be doing something wrong because it is not working. It is returning a null value.

Java Prototypes:

*+++++++++++++++++++++++++++++++
* new_jMap
* Create a new Java Hashmap object
*
* Returns the new Java HashMap object
*+++++++++++++++++++++++++++++++
D new_jMap...
D PR like(jMap)
D ExtProc(*JAVA
D :'java.util.HashMap'
D :*CONSTRUCTOR)
*++++++++++++++++++++++++++++++
* jMap_put
* Add a key and a value to a hashmap
*
*++++++++++++++++++++++++++++++
D JMAP_put...
D PR like(jObject)
D EXTPROC(*JAVA
D :'java.util.HashMap'
D :'put')
D key like(jObject)
D value like(jObject)

And the RPG wrapper prototype:

D rre_jMap_put...
D PR like(jObject)
D prMap like(jMap)
D prKey like(jObject)
D prValue like(jObject)
RPG Wrapper program:
*-------------------------------------------
* Add elements to a Hashmap
*
*-------------------------------------------
P rre_jMap_put...
P B EXPORT
D rre_jMap_put...
D PI like(jObject)
D peMap like(jMap)
D peKey like(jobject)
D peValue like(jObject)
D

/free

peMap = JMAP_put(peMap:peKey:peValue);

return peMap;

/End-free
P E

Finally when I call it in my program (relevant code):

lReParam = new_jMap();
lkey = new_String('selectName');
lvalue = new_String('BALL');
lReParam = rre_jMap_put(lReParam:lkey:lvalue);

The thing that I am uncertain about is that when I code in Java, I act on the object directly rather than passing it back and forth (it may be a shorthand way, I don't know). So in Java I would do this:

HashMap reportParameters = new HashMap();
reportParameters.put("selectName", "BALL");

But even changing the RPG code above to this:

lReParam = new_jMap();
lkey = new_String('selectName');
lvalue = new_String('BALL');
rre_jMap_put(lReParam:lkey:lvalue);

Has the same result which is a null value for the key/value pair.

I am missing something. Any suggestions?
Thanks,

Pete




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.