Access Modifier Issues

Richard Warburton richard.warburton at gmail.com
Fri Jan 9 14:11:28 UTC 2015


Hi gents,

Not sure if its a high priority to fix the access modifier problems at the
moment, but there still seems to be a bug with Peter Levart's default hack
which I didn't see reported in the other thread.

public class Default<any T> {

    private T value;

    private Default() {}

    public static <any T> T value() {
        return new Default<T>().value;
    }

    public static void main(String[] args) {
        int i = Default.value();
        System.out.println(i);
        long l = Default.value();
        System.out.println(l);
        Object o = Default.value();
        System.out.println(o);
    }

}

When running:

Specializing method Default$value${0=I}.value()Ljava/lang/Object; with
class=[] and method=[I]
Specializing Default${0=I}; searching for Default.class (not found)
Specializing Default${0=I}; searching for Default.class (found)
Exception in thread "main" java.lang.IllegalAccessError: tried to access
method Default${0=I}.<init>()V from class Default$value${0=I}/793589513
        at Default$value${0=I}/793589513.value(Default.java:8)
        at Default.main(Default.java:12)

Looks like its workaround-able by making both the constructor and value
field public.

I think this also exposes something I don't understand here. My impression
was that "Default${0=I}" was the specialisation of the class Default s.t.
its first type parameter is an int. So what is "Default$value${0=I}"?

regards,

  Richard Warburton

  http://insightfullogic.com
  @RichardWarburto <http://twitter.com/richardwarburto>


More information about the valhalla-dev mailing list