1

I have a String named firstName. This string has a value of "Matt". I then have a second String named lastName with a value of "getLastName()". Both of these String are stored in a database and I'm attempting to build a line of code dynamically. The line of code needs to say:

 firstName + getLastName();

Is there a way to get java to read the value of lastName (which is getLastName()) as a method instead of as a value of a string?

mattt
  • 35
  • 5
  • 2
    https://docs.oracle.com/javase/tutorial/reflect/index.html. Storing Java method names in a database and using reflection this way is a huge design smell, though. Your data shouldn't depend on implementation details. You should be able to change the implementation, or even change the language used to write your application, without having to change your data. – JB Nizet Oct 16 '18 at 20:21
  • On what object would `getLastName()` be called? If that is the value of `lastName`, wouldn't it just get it's own value? – Andreas Oct 16 '18 at 20:31

0 Answers0