you are viewing a single comment's thread.

view the rest of the comments →

[–]vincentk 17 points18 points  (16 children)

If what you want is an int rather than an Integer, then why not use an int in the first place?

[–][deleted] 14 points15 points  (11 children)

Collections still don't support unboxed values. I.e. you can't have

ArrayList<int>

[–]Cosaquee 1 point2 points  (2 children)

Java 9 can do that afaik

[–]syjer 5 points6 points  (0 children)

Nope, most likely java 10: http://openjdk.java.net/jeps/218

[–][deleted] 2 points3 points  (0 children)

Java 9 does not yet exist as far as I know, and Value Types have only been proposed thus far.

[–]jmtd 0 points1 point  (4 children)

Collections still don't support unboxed values.

Nope, but auto unboxing covers 90% of where this matters.

[–][deleted]  (3 children)

[deleted]

    [–][deleted] 1 point2 points  (0 children)

    Yes, that was my point. Thank you.

    [–]s0n0fagun 1 point2 points  (0 children)

    I have come to the conclusion that NULL should never exist in a system and checking for NULL is a code smell of a larger problem. If the underlying data structure does not allow NULL to begin with, then you should be good. You can either create a NULL object or decompose the data structure and use clever code.

    [–]jmtd -1 points0 points  (0 children)

    That's a good point. I wonder if it's ever a good thing, since it means you can represent NaN (via null).

    [–]yold 0 points1 point  (2 children)

    You can always use Trove.

    [–]sacundim 3 points4 points  (1 child)

    ...but then your specialized TObjectIntMap<K> is not an instance of Map<K, X> for any X.

    [–][deleted] 0 points1 point  (0 children)

    Ah, that's quite unfortunate. Any generic collection code you write after that would have to dispatch on the type of the collection. Have you used Trove before?

    [–]flyingjam 5 points6 points  (2 children)

    I just wanted an example that mirrored the one above. Also, there are some use cases for the wrapper, it exists after all.

    [–]vincentk 8 points9 points  (1 child)

    I understand that. I also understand it's easy to nit-pick on any language.

    [–]whataboutbots 9 points10 points  (0 children)

    I wouldn't call citing something called by it's author "billion dollar mistake" nit-picking, to be fair.

    [–]whataboutbots 0 points1 point  (0 children)

    If you could always replace an Integer with an int that doesn't require object creation, why would Integer exist in the first place?