Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Problem with static intertype declaration and

Jeffery, Bo, Thanks for your respond.

For non static members and functions I use an empty interface to intertype
the same members and functions to more then one class. The body of the
method is for all classes the same. This works fine.

But what I want to do also, is intertype the same static member and static
function to more than one class. (This is necessary because the classes need
the static member and function). Is there a way to do this generic. 
Instead of the following code:

Class Book {}
Class Library{}
Class Category{}

aspect aAspect 
{
   public static String Book.aString = getString();
   public static String Library.aString = getString();
   public static String Category.aString = getString();
 
   public static final String Book.getString()
   {
       return "AString";        
   }
   public static final String Library.getString()
   {
       return "AString";        
   }
   public static final String Category.getString()
   {
       return "AString";        
   }
 }

Greetings,

Bas

Message: 1
> Please have a look at the following code:
> 
> package untitled4;
> public interface Interface1{}
> 
> package untitled4;
> class Untitled1
> {
>     public static void main(String args[])
>     {
>     }
> }
> 
> package untitled4;
> aspect aAspect 
> {
>   declare parents : Untitled1 implements Interface1;
> 
>   private static String Untitled1.aString = getString();
> 
>   private static final String Interface1.getString()
>   {
>       return "AString";        
>   }
> }
> 
> When I run this code the following exception occurs:
> java.lang.ClassFormatError: untitled4/Interface1 (Illegal method
modifiers:
> 0x409)
> 
> Questions:
> - Why does the error occur? (The ajc compiler doesn't give an error or
> warning) Is this a aspectJ bug?
> 
> - Why is it not possible to intertype a static field to an interface. 
> (I want to add a static field to more then one class, the classes
implements
> the same interface)
> 
> Greetings,
> 
> Bas

This error occurs because you've introduced a static member onto an 
interface,

public interface Interface1 {
     public abstract static java.lang.String
                     ^^^^^^
       ajc$interMethodDispatch2$aAspect$getString();
}

and ajc have allowed this... looks like a bug.  But what were you trying 
to do? It's not evident from your example.  Why would you want to 
introduce a static member on all instances of an interface?

Jeff
-- 
Jeffrey Palm --> http://www.ccs.neu.edu/home/jpalm

--__--__--



Back to the top