Is it possible to change a String of a method at run time?

4

If I have a fixed String within a method can it be altered using reflection or something like that? Example:

public static void main(String[] args) {
    String nome = getName();
    boolean valid = isValidName(nome);
    if (valid) {
        System.out.print("Seu nome é valido!");
    } else {
        System.out.println("Seu nome é inválido!");
    }
}

I would need to change the message "Your name is invalid!" to "Invalid Name." this at runtime, ie after compiling and running the program I would need to edit this message.

I'm working with an API that is in English, the client has asked me to translate it 100%. The API has configurable messages, where you can simply go to the lang.txt file and change the messages, however there are some messages that are not available in this lang.txt file so I had to edit them using reflection, but I came across some messages which are "fixed" (I do not know if this is the correct term) and I would need to edit these messages ... these messages follow the example above.

    
asked by anonymous 20.08.2018 / 17:53

1 answer

1

You do not necessarily need to use reflection for this, you can create your own API .

I already had to do this, with several old and unsupported jars whose source code nobody owned, usually internal, but also happened to need to change a jar of third, that neither the site existed anymore.

Use the jd-gui program (or any decompiler you like) to see all the source code of your jar.

Create a new project in your IDE and copy the decompiler codes to there, make your modifications and export them to a new file.

I believe that this is even easier, you can even change it to make all strings load from a properties.

    
20.08.2018 / 20:20