There is no operator overloading in Java. It is implemented in other JVM languages like Scala, but this is a bit off-topic here.
BTW, I did not say it was impossible, just that it will probably never happen in AspectJ. ;) What you show is normal method interception, not operator interception. Smthe example is not really relevant. Besides, you never know what a compiler might do with arithmetic operations optimisation-wise. Multiplication by powers of 2 might get replaced by left-shift operations (just making up an example). I do not even say that what you suggest might not be useful in so e rare and special cases, I just think it is way to fine-granular for AOP purposes. I think your example is rather academic than useful in daily work. Alexander Kriegisch Am 07.01.2013 um 10:34 schrieb "M. P." <free...@abv.bg>: >>> For example I'd like to be able to select integer subtraction: > > >>> Integer i = 5; > >>> Integer j = 2; > >>> Integer r = i - j; > > >>> Maybe if Java supported operator overloading that would be fairly easy. > > >>> 1. So is something like this possible now? I'm pretty sure it is not. > > >> You are right, it is not possible. > > >>> 2. Would this be possible to implement? How? Effort? > >>> 3. Is something like this planned for future AspectJ versions? > > >> I cannot speak for the developers, but I do not think you will ever see this >> feature in AspectJ. > > > > >> Regards > > > I'm not sure I see why not. Please consider the following example: > > public aspect StringConcat { > public pointcut concat() : call(* java.lang.StringBuffer.append(..)); > > before() : concat() { > System.out.println("About to concatenate!"); > } > } > > public class Tester { > > public static void main(String[] args) { > String a = "a"; > String b = "b"; > System.out.println(a + b); > } > } > > When main() is executed the result is: > ======================= > About to concatenate! > ab > ======================= > > So we actually have a real example where the + operator is overloaded and the > resulting code is directly in the client byte code. > Now I'm not too familiar with the Java byte code spec but I don't see why the > same cannot be done for e.g. Integer or event the primitive types? > > Thank you. > > MP > _______________________________________________ > aspectj-users mailing list > aspectj-users@eclipse.org > https://dev.eclipse.org/mailman/listinfo/aspectj-users _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users