[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

It is not easy to weave the classes in JDK and it may not be legal.
With a quick search I can only find
http://aspectj.2085585.n4.nabble.com/IDT-in-JDK-classes-How-to-enable-java-weaving-tc2086437.html#none.
Please check list archives and docs for details.

On Thu, Jun 7, 2012 at 11:53 PM, MattOng <ongbp@xxxxxxxxx> wrote:
> 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.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users