3 ms·
Just have a generic abstract class with the required public interface, then have two implementations of it, generic one, and a special one for trivially copyabl
by lostmsu 8y ago
Just have a generic abstract class with the required public interface, then have two implementations of it, generic one, and a special one for trivially copyable types. Then you can have a factory, that creates an instance based on the element type. Can be done in Java and C# alike.
- Koshkin 8y agoThe post gives an example of using an interface with static dispatch. This is in contrast with a regular interface (an abstract class) which implies the use of dynamic dispatch.
- lostmsu 8y agoI don't think it matters in the scenario though. The cost of dynamic dispatch will be negligible in comparison to remote call costs, even into a different process on the same machine. Besides, there are techniques to avoid dynamic dispatch for generic specializations, at least in C#.
- smoothdeveloper 8y agoAnd even more techniques in F# in it's type system and inlining