I have a class that currently has several methods that take integer parameters. These integers map to operations that the application can perform. I’d like to make the class generic so that the consumers of the class can provide an enum type that they have with all the operations in it, then the methods will take parameters of that enum type. However, I want them to be able to not specify a generic type at all, and have it default back to integers with no change in syntax from the current way. Is this possible?
I have a class that currently has several methods that take integer parameters. These
Share
You can’t do it in the definition of the class:
If really value the implicitness of the default type being int, you’ll have to do it with a static factory method, although I don’t see the value of it.
See below for how you really don’t benefit from the above.
If you want to take it even farther, you can create a static factory class that will solve this, but that’s an even more ridiculous solution if you’re doing it for no other reason than to provide a default type: