Suppose I have class Foo which contains several fields of type String. Is there a way which I can iterate over each of these fields for a given Foo object and map a String function to each? I am looking for a solution which uses a lambda expression, something like the following:
Foo bar = new Foo(field1, field2, field3);
//here is where I am unsure
bar.forEachField( field -> someFunc(field));
I am having trouble finding an example which goes through the fields of an object as opposed to some collection. I have tried to add each field to an ArrayList and then use replaceAll() on each String, but since each String is immutable this will have no affect on my actual Foo object.