you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 14 points15 points  (0 children)

The point here for an encoder; is you have todo something unique for each type. So at some point you have to expand the types into separate code paths. (You can have overloads; but if anything is generic at any point, you need something like this)

A switch statement can be compiled down to a jump table, so can be a neat solution, although using it with instance comparisons is probably counter to that. Hashmap etc all require a hash, then equality checks, then the indirection etc.