Why are public static final array a security hole?

后端 未结 8 1663
盖世英雄少女心
盖世英雄少女心 2020-12-13 13:21

Effective java says:

// Potential security hole!

static public final Thing[] VALUES = { ... };

Can somebody tell me what is t

8条回答
  •  暖寄归人
    2020-12-13 13:22

    Note that a nonzero-length array is always mutable, so it is wrong for a class to have a public static final array field, or an accessor that returns such a field. If a class has such a field or accessor, clients will be able to modify the contents of the array.

    -- Effective Java, 2nd Ed. (page 70)

提交回复
热议问题