0

Say that I have a class with public fields field1 and field2 which are strings

I want to have a function that takes 2 parameters, the first is the field and the second is the new string.

Can I create an enum for field1 and field2 and someone link the enum to the field so that whenever I use the function

function(FIELDS.field1, "newString")

It will know that FIELDS.field1 relates to this.field1 and FIELDS.field2 relates to this.field2.

basically my question is can I create a dynamic setter? because sure I can do

field1Setter and field2Setter but I will have a let of fields and do not want to create a setter for each

Contentop
  • 1,163
  • 3
  • 20
  • 43

0 Answers0