-1

I want to modify parameter value passed to a particular method of a java class. Here is the java file:

package config;

public class ABC extends LineAvailabilityNew
{

     public void doMessageDataOverrides() throws MessageHandlerExcection
     {
          super.doMessageDataOverrides();
          setWorkingLineQty("21");
          setStoppedLineQty("10");
     }
}

Now I want to modify parameter value for setWorkingLineQty("21") i.e 21 to say 35. The value is to be modified from another java class.

As of now, my other java class is achieving this by performing below activity:

  1. Reading the parameter value using javaparser.

  2. Get the file content

  3. Create a copy of file content and using normal String replace function, replace setWorkingLineQty("21") to setWorkingLineQty("35")

  4. Replace the file using File class

Note: I cannot make any changes to ABC class. Would appreciate answers through any other way.

Neha S
  • 283
  • 1
  • 3
  • 17

2 Answers2

0

where is this setWorkingLineQty("21"); method defined? in the same class?

You can pass arguments in the doMessageDataOverrides() method as

public class ABC extends LineAvailabilityNew
{

     public void doMessageDataOverrides(String x, String y) throws MessageHandlerExcection
     {
          super.doMessageDataOverrides();
          setWorkingLineQty(x);
          setStoppedLineQty(y);
     }
}
OnePunchMan
  • 720
  • 15
  • 33
0

modify the prarameter meaning ? and where is the setWorkingLineQty() function ?.

-If you are trying to change original values that are passed as parameters to the function you cannot (Java is pass by value)

-If you just want to reassign some new value to your parameter you directly can like:-

void foo(A){

A="34";
}
Mustafa sabir
  • 4,130
  • 1
  • 19
  • 28