I have the following classes:
Class A {}
Class B: A {}
Class C: A {}
Now, I have 2 functions that fill either B or C with data. At the moment, 2 functions are required because one creates New B() and the other New C().
I would like just one function that I can tell to use either B or C. I cannot just send a class and tell it to be filled, the called function needs to be able to create the classes on the fly.
You can write a generic function with a
newconstraint on the type argument:You can now call this method like this: