Comment by cbsmith

4 days ago

I didn't like how this essay misunderstood the design principles in Java's class files. With dynamic binding to the runtime, you can't know for certain the layout of a data structure in memory (e.g. what is the ideal memory alignment?). If the class file is untrusted, you can't even be sure you have a valid data structure in the first place. So allocating the array and then assigning elements one at a time is what you do.

It also appears to be a nonsensical complaint in general. Why abuse .class files for data storage when you can choose any data format you like?

I've only seen this pattern used in contexts, where there is no filesystem to begin with.

  • > Why abuse .class files for data storage

    The only alternative is to have the data in a separate file, which needs to be available, read in, and parsed. .NET/CLR provides a mechanism to bake large objects into the assembly and I don't see that as abusive. It's way more convenient when you can treat the object as being “just there”.

    • Well, jars can have resource files included - I would say this is a more-than-solved problem.