Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of johanvdb (1872)

Thursday August 07, 2003
07:22 PM

i++ fails ( ... java bashing )

[ #13984 ]

I did not make it to YAPC::Europe::2003 ... that is a bit of a sad thing, but hey, my daugther got sick on thursday evening - nothing serious , though - so my wife was very happy having me around. So I guess that not going to YAPC was rather a good thing!

Anyhow ... I'm a bit annoyed with java, although i need to do *stuff* with it for my day job. The last week I've been busy using aspects (AspectJ, http://www.eclipse.org/aspectj) to do some code coverage profiling on file system access. Anyhow, I was a bit thorn away by the fact that the next piece of code does not work:

Integer i = new Integer(5);
i++;

This does not work, neither has the Integer object an add, substract or Integer.doSomethingUsefull() method. Curious not, that a language which was originally targetted to embedded systems has so much trouble getting its primitive types in order. I need to have an integer object, because I needed top keep a hash (HashMap), linking a name to a counter (${$key}++) .... it expects an Object as its key and value paremeter in the put method (HashMap.put(key, value)). Anyhow, a colleague told me he uses an array with one element for this. A straight int type will not work, as it is a primitive integer type and no Integer object.

Johan

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • ...is to use a one-element array. Then with the minor pain of an extra "[0]", you can use normal arithmetic ops. Of course, you still have to either cast the result of get() or create a new subclass of HashMap that does the casting for you. There's no silver bullet for Java's loathesomeness. /s

    BTW, the one-element array trick can also be used to get around the stupid restriction about not allowing access to non-final variables in anonymous classes.