boxing ???

B

blueparty

Is it possible that some newer version of JRE might have a problem with
this:

HashMap m=new HashMap();
double d=0.789;
m.put("number",5);

It works on my JDK (1.5), but I suspect it might not work on other
machine with newer JRE, not sure. Anyone had the same experience ?

B
 
A

Andreas Leitgeb

blueparty said:
Is it possible that some newer version of JRE might have a problem with
this:
HashMap m=new HashMap();
double d=0.789;
m.put("number",5);

If you rely on boxing (since 1.5), you could just as well
parameterize the HashMap (generics also since 1.5):

Map<String,Integer> m = new HashMap<String,Integer>();
m.put("number",5);

(dunno, what role the double is supposed to play here)
It works on my JDK (1.5), but I suspect it might not work on other
machine with newer JRE, not sure. Anyone had the same experience ?

If it is *compiled* with a javac version x, it will *run* with jre
version y, if y>=x. (y<x may work, too, but most often doesn't)

One may encounter problems when compiling old code with a newer
compiler. (in that case, option "-source 1.5" should help, short
of just making the source >1.5 clean)
 
R

Roedy Green

Is it possible that some newer version of JRE might have a problem with
this:

HashMap m=new HashMap();
double d=0.789;
m.put("number",5);

If you want autoboxing, you need generics to tell Javac what sort of
Object to put in the HashMap.

See http://mindprod.com/jgloss/hashmap.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

Never discourage anyone... who continually makes progress, no matter how slow.
~ Plato 428 BC died: 348 BC at age: 80
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top