Jim LaGrone <jlagr...@cs.uh.edu> wrote on 09/19/2009 03:57:43 PM:

> I'm trying to use HashMap. Since there is no explanation about the 
> API, I'm just guessing at things. I thought I could use this class to 
> map Key -> Value.
> 
>    val hash = new HashMap[Int,Int](size);
>    hash.put(k,v);
> 
> But when I try to retrieve the value I get a Box object (call to hash 
> (k) returns x10.lang.Box object). I need an Int. How is this done? The 
> spec mentions unboxing Box[T] to T but gives no explanation of how.

The only reason hash.get() returns a Box is because it wants to be able
to return a null value.  You need to check the return value for nullness,
and then "unbox" (i.e., extract the contents of the box), by accessing
the "value" property of the box.

Hope this helps,
        Igor
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to