#1751 Newbie Question: Constant Array Question

claytonwohl Thu 12 Jan 2012

How do I define a constant array of ints? In Java, I would do the following. Ideally, I would like to to take advantage of Fantom's const qualifier (which Java doesn't have).

protected final static int[] exampleArray = { 3, 4, 5, 6, 7 };

DanielFath Thu 12 Jan 2012

Sure it is.

a:= [1,2,3,4]
 [1,2,3,4]
b:= [1,2,3,4].toImmutable
 [1,2,3,4]
a.add(5)
[1,2,3,4,5]
b.add(0)
 sys:ReadonlyErr: List is readonly

If your want your fields to be immutable declare then static and const (in fact all static field must be const).

claytonwohl Fri 13 Jan 2012

works perfectly. thanks!

Login or Signup to reply.