Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Custom Autoboxing

This is not possible.  Boolean is a final class, and so MyBoolean
cannot be a subclass of it.  The return type of around advice must be
the original type (or a narrowing of it) because it must be statically
type safe wherever the advice is applied.  Therefore the advice you
wrote can not compile.

--a

On Tue, Nov 4, 2008 at 11:14 AM, Keith Kowalczykowski <keith@xxxxxxxxxxx> wrote:
> Hi Everyone,
>
>    I'm new to the list, so I apologize if this is the wrong place to ask
> such questions. I have searched the list, and googled around, but have not
> found any information about my question yet.
>
> I'm wondering if it is possible to implement some sort of custom autoboxing
> using aspectj. For example sake, lets say:
>
>  MyBoolean b = true;
>
> Where MyBoolean is a custom implementation of essentially java.lang.Boolean
> (I know this is pretty pointless, but its just for example sake).
>
> Intuitively, it seems like this should be completely possible, as I could
> declare a pointcut on the set of MyBoolean, and then declare around advice
> which takes the boolean and returns a MyBoolean. The problem, however, is I
> still get a compiler error that "boolean is not assignable to MyBoolean".
>
> So I'm wondering if anyone point me in the right direction if 1) what I'm
> saying is even possible and 2) if so, what I'm missing.
>
>
>  Thanks,
>     Keith
>
>
> Here is a quick aspect I've written to test this:
>
>    pointcut setBool(boolean newval): set(MyBoolean *) && args(newval);
>
>   MyBoolean around(boolean val) : setBool(val)
>
>    {
>
>       return new MyBoolean(val);
>
>    };
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top