Alternatives for annonymous inner classes in Java
<p>Hello<br>
Given the entities below - is it possible to somehow avoid using anonymous inner classes as marked by <code>/***** Get rid of this annonymous inner class ******/</code>.
The problem is that "<code>SomeEntity</code>" can contain hundreds of fields and there are multiple classes which implement this interface, each of them requiring meta information. This means that there are thousands of anonymous inner classes begin generated causing my build time to be really really slow and for the boot up time for the system to be really slow as the class loader loads all the classes. </p>

<p>I can't use reflection because my classes get obfuscated before release</p>

<p>Any ideas would be greatly appreciated.</p>

<p>Kind Regards</p>

<pre><code>public interface SomeEntity {

    ///// boolean someField
    // getter
    void someField(boolean someField);

    // setter
    boolean someField();

    final static String someField = "someField";

    ///// boolean someField2
    // getter
    void someField2(int someField2);

    // setter
    int someField2();

    final static String someField2 = "someField2";

}


public class SomeEntityImpl implements SomeEntity {
    boolean someField = false;
    int someField2 = 0;

    @Override
    public void someField(boolean someField) {
        this.someField = someField;
    }

    @Override
    public boolean someField() {
        return this.someField;
    }

    @Override
    public void someField2(int someField2) {
        this.someField2 = someField2;
    }

    @Override
    public int someField2() {
        return someField2;
    }
}


public class SomeEntityMeta {

    public static interface Meta&lt;T&gt; {
        T get(SomeEntity x);
        void set(SomeEntity x, T t);
        void copy(SomeEntity from, SomeEntity to);
    }

    Meta&lt;Boolean&gt; metaForSomeField = new Meta&lt;Boolean&gt;() {

        @Override
        public Boolean get(SomeEntity x) {
            return x.someField();
        }

        @Override
        public void set(SomeEntity someEntity, Boolean newFieldValue) {
            someEntity.someField(newFieldValue);
        }

        @Override
        public void copy(SomeEntity from, SomeEntity to) {
            to.someField(from.someField());
        }

    };
    Meta&lt;Integer&gt; metaForSomeField2 = new Meta&lt;Integer&gt;() {

        @Override
        public Integer get(SomeEntity someField2) {
            return someField2.someField2();
        }

        @Override
        public void set(SomeEntity someEntity, Integer newFieldValue) {
            someEntity.someField2(newFieldValue);
        }

        @Override
        public void copy(SomeEntity from, SomeEntity to) {
            to.someField2(from.someField2());
        }

    };

    Map&lt;String, Meta&lt;?&gt;&gt; metaMapForAllFields = new HashMap&lt;String, Meta&lt;?&gt;&gt;() {
        private static final long serialVersionUID = 1L;
        {
            put(SomeEntity.someField, metaForSomeField);
            put(SomeEntity.someField2, metaForSomeField2);
        }
    };

}    
    // used as follows:


        public final static void main(String[] args) {
            SomeEntity someEntity = new SomeEntityImpl();
            SomeEntityMeta entityMeta = new SomeEntityMeta();
            /// 
            Map&lt;String, Object&gt; fieldNameValueMap = getFieldNameValueMapFromExternalsSystem();

            for ( Entry&lt;String, Object&gt; fieldNameValueEntry : fieldNameValueMap.entrySet()) {
                Meta&lt;Object&gt; meta = (Meta&lt;Object&gt;) entityMeta.metaMapForAllFields.get(fieldNameValueEntry.getKey());
                meta.set(someEntity, fieldNameValueEntry.getValue());
            }
        }   
</code></pre>
