Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to add methods to java.lang.String

public final class MyString{}

public privileged aspect StringRedef{
    private interface Redef{}

    // allowed *even* if MyString is *final*.
    declare parents: (MyString) implements Redef;
    *// NOT allowed even String is also final.*
    declare parents: (java.lang.String) implements Redef;    

    public String Redef.ltrim(){
        return "#LTRIMED";
    }
}

public class StringRedefUser
{
    public static void main(String[] args)
    {
        String string="ABCDEFG";
        MyString mystring=new MyString();
        // This is allowed and has no compilation error.
        System.out.println("LTRIM:"+mystring.ltrim());   
        // This is NOT allowed because it is not expose to weaving.
        System.out.println("LTRIM:"+string.ltrim());
    }
}
======================================

How to expose java.lang/javax.lang or any classes to weaving?



--
View this message in context: http://aspectj.2085585.n4.nabble.com/How-to-add-methods-to-java-lang-String-tp4650376p4650378.html
Sent from the AspectJ - users mailing list archive at Nabble.com.


Back to the top