How can I get my parameter object AFTER my method has modified the parameter?

Presto

I am trying to use Spring AOP/ AspectJ to access my parameter after the method has done some modifications to it.

example:

public void changeValueOnFoo(Foo fooToModify) {
    fooToModify.changeValue("1");
}

@Around("execution(* com.my.FooFunctions.changeValueOnFoo(..)")
public void interceptFoo(ProceedingJoinPoint jp) {
    Foo f = (Foo) jp.getArgs()[0];
    System.out.println(f.getValue()); // will print "1"
    jp.proceed(); 
    Foo modifiedf = jp.getArgs()[0];
    System.out.println(modifiedF.printValue()); // will print "2"?
}

Is something like this possible? Procceding, then recalling the parameter after it's been modified by the method? Or does getArgs simply hold a pointer to the original state of the parameter so this isn't possible?

dreamcrash

Is something like this possible? Procceding, then recalling the parameter after it's been modified by the method?

Yes, it would work, because getArgs() holds the reference to the object passed as parameter (i.e., Foo). So any changes made to the fields of that object will be visible to the outside has it would be using plain Java.

Or does getArgs simply hold a pointer to the original state of the parameter so this isn't possible?

That "simply" makes it possible to actually see the changed state.

Bear in mind, however, that this will only work for object types, since they are called by reference. This will not work for primitives data types (e.g., int, float, ...), or immutable objects (e.g., Integer, String and so on).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I pass List in my method parameter?

How can I get a method that has an out parameter?

How can I insert a variable into the resulting url parameter string after submitting my GET form?

How can i get my url parameter right on Javascript?

How can I prevent my parameter in my setter method from being changed?

How can I get the generic type parameter of the 'this' parameter in an extension method?

In TypeScript, how can i get a generic type parameter to be inferred in a method that has multiple type parameters?

How can I create my own exception if an object parameter is null in C#

How can I mock an async protected method that has a parameter?

How can I get the parameters of a function from a function passed as a parameter to my function, in Lua?

how can I get requests(module name) data parameter to my dJango server?

How can I get my Ruby on Rails API controller to receive an array of values for a query parameter?

C# Generics How Can I get the type passed as an argument for a generic method with no object type as a parameter?

How can I call some code after a property on my state object has been defined?

How can I pass in a parameter to my TestCase in Django?

How can I add a parameter to my url, without reload the page?

How can i send an extra parameter with my link_to

How can I validate that a parameter is one of my Azure resource groups?

How can I send my Vec to a function taking an Iterator as a parameter?

How can I change a CPLEX parameter in my Julia code?

How can I send results of a test as a parameter to my python script?

How can I get resharper to know that my variable is not null after I have called an extension method on it?

How to place my method parameter into the array property

How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?

How can i access the parameter which are sent using the get method?

How can i get the parameter values of an anonymous method passed as a func?

A java method that has a generic parameter- why can't I pass an object with a generic parameter that is a subclass of the method arguments?

How can i get class from Object parameter?

How I can get object as parameter from Servlet

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive