Externalizable array in Java

359 Views Asked by At

I need to send over the network an array of Externalizable objects for maintainability and performance reasons (Serializable is not enough).

The documentation says that all arrays in Java are Serializable. Is it possible to have an array that is also Externalizable? If not, what are the workarounds to still have benefits of Externalizable and send a bunch of these objects over the network?

1

There are 1 best solutions below

2
On

You can't easily make arrays externalizable (I am guessing it might be possible with byte-code manipulation or something).

However, what you probably are doing is not sending the raw array, but sending some other class that includes the raw array. So you can implement Externalizable in that class such that it can send and receive all its contents in the format you desire.

In the case that the array is really the only thing you want to send, this other class could be a simple wrapper.