Brian's Waste of Time

Sun, 11 Jan 2004

Is it bad if I use pointers in Java?

I frequently find myself writing code like:


    final boolean[] val = new boolean[] { false };
    mixed.forEach(new Closure()
    {
        public void execute(Object o)
        {
            val[0] = true;
        }
    });

in my unit tests for quick checks in order to get around the lack of explicit pointers in Java so that I can toggle a boolean in an anonymous inner class.

This feels like an awful hack, but does anyone know a better idiom?

9 writebacks [/src/java] permanent link