Generalise toJavaArray to all primitive Java types.