On Sat, Nov 29, 2008 at 6:17 PM, JMan <[EMAIL PROTECTED]> wrote:

>
> Consider these 2 interfaces:
>
> - PackagePrivateInterface.java
>
> package test;
>
> interface PackagePrivateInterface {
>    public void myPublicMethod();
> }
>
> - PublicTagInterface.java
>
> package test;
>
> public interface PublicTagInterface extends PackagePrivateInterface {
> }
>
> And these 2 classes:
>
> - Factory.java
>
> package test;
>
> public class Factory {
>    public static PublicTagInterface newImpl() {
>        return new PackagePrivateClass();
>    }
> }
>
> - PackagePrivateClass.java
>
> package test;
>
> class PackagePrivateClass implements PublicTagInterface {
>    PackagePrivateClass(){
>    }
>    public void myPublicMethod() {
>    }
> }
>
> Now examine the following snippet of clojure code:
>
> (import '(test Factory PublicTagInterface))
>
> (def foo (. Factory newImpl))
>
> (. foo myPublicMethod)
> java.lang.IllegalAccessException: Class clojure.lang.Reflector can not
> access a member of class test.PackagePrivateInterface with modifiers
> "public abstract" (NO_SOURCE_FILE:0)
>
> Also "can not" should be spelled "cannot."
>

That message is coming from the Java reflection library, not Clojure.

As defined above, the method cannot be called via reflection. This is
because the resulting type of myPublicMethod in PublicTagInterface is:

public abstract void test.PackagePrivateInterface.myPublicMethod()

Reflection will not let you call methods of private classes.

If PublicTagInterface redeclares the method as follows:

public interface PublicTagInterface extends PackagePrivateInterface {
       public void myPublicMethod();
}

then the type is:

public abstract void test.PublicTagInterface.myPublicMethod()

and it works fine.

There is nothing I can do about this in Clojure.

Rich

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to