Here are a set of questions that one of our customers asked us recently. They were concerned that our library is not friendly to Java wrapper types (java.lang.Integer, java.lang.Character, java.lang.Boolean and so on). They asked us to explain.
Q> Why supporting primitive types as int, bool as well as their arrays is not enough in Java world? Is there anything in the picture that I am missing?
A> This is because traditional Java doesn’t have the concept of passing primitive types by reference (i.e. /** @ref */ in J#).
The only ways to pass primitive types by reference in traditional Java are:
1. Pass a 1x1 array or the primitive type
2. Pass a wrapper type (int is wrapped by java.lang.Integer, boolean by java.lang.Boolean and so on)
Q> It seems like this is just a boxing type why would be an issue not supporting those?
A> Traditional Java doesn’t have the notion of boxing either!
You cannot do the following in traditional Java:
int i = 0;
Object obj = (java.lang.Integer)i;
But in J# you can do the following:
int i = 0;
Object obj = (System.Int32)i;
Q> It sounds like the existence of @ref makes the use of Integer and the same useful just for maintaining Java compatibility (if someone really needs that) otherwise using the primitive types should be enough.
A> Yes you are right except that @ref int makes use of System.Int32 and not java.lang.Integer.