File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes pattern for unmodifyable array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "pattern for unmodifyable array" Watch "pattern for unmodifyable array" New topic

pattern for unmodifyable array

Gytis Jakutonis
Ranch Hand

Joined: Feb 02, 2004
Posts: 76
I need to define final static array (with file signature bytes in my case), ant I'm not sure how to protect array from modifications. If I use simple form:

then malicious code may change signature elements:

So I came up with this idea:

Maybe there is some pattern for this problem, or maybe new jdk 1.5 has some standard elements, which slolve the issue?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Better than a pattern, the java.util.Collections class contains methods to mark collections as unmodifiable. Have a look at those.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: pattern for unmodifyable array
It's not a secret anymore!