JavaMemoryModel: Access to final members by super through overloaded methods

From: Victor Toni (javaMemoryModel@vitoni.de)
Date: Tue Feb 22 2005 - 15:37:24 EST


I had an complex version of this used for some kind of recursive data
model building.

My initial version called super() which itself called an overloaded method.
It seems unusual (maybe because it doesn't work in the current model
:-) but at first it appeared as an elegant approach.

I remember trying something alike for JTable (which itself seem squite
broken) to have a delegating TableModel but it failed because of the
overloading of a super.method() which got called in the constructor.

Would something like this work within the new memory model?

I looked for examples but everything I found had only primitives which
are treated differently (surprise, surprise).

Kindest regards,
Victor


import java.util.HashMap;
import java.util.Map;

public class SubClass
        extends SuperClass {

        private final Map map = new HashMap();

        private final int value = -10;

        public SubClass() {
                super();
                writeMembers();
        }

        public static void main( final String[] args ) {
                new SubClass();
        }

        protected Map getMap() {
                return map;
        }

        protected int getValue() {
                return value;
        }

}

import java.util.Collections;
import java.util.Map;

public class SuperClass {
        public SuperClass() {
                writeMembers();
        }
        
        protected final void writeMembers() {
                System.err.println(getMap());
                System.err.println(getValue());
        }

        protected Map getMap() {
                return Collections.EMPTY_MAP;
        }
        
        protected int getValue() {
                return 20;
        }
}

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:09 EDT