Integer.class vs int.class

Integer.class is, as you say, a reference to the Class object for the Integer type. int.class is, similarity, a reference to the Class object for the int type. You’re right that this doesn’t sound right; the primitives all have a Class object as a special case. It’s useful for reflection, if you want to tell … Read more

Are Java primitives immutable?

Will this allocate a new memory location? Or just replace the original value? Java does not really make any guarantees that variables will correspond to memory locations; for example, your method might be optimized in such a way that i is stored in a register — or might not even be stored at all, if … Read more

How to serialize Java primitives using Jersey REST

Have a look at Genson.It helped me a lot with a similar problem.With Genson you could use generics like int,boolean, lists and so on…Here is a quick example. @GET @Produces(MediaType.APPLICATION_JSON) public Response getMagicList() { List<Object> objList = new ArrayList<>(); stringList.add(“Random String”); stringList.add(121); //int stringList.add(1.22); //double stringList.add(false); //bolean return Response.status(Status.OK).entity(objList).build(); } This will produce a valid … Read more