A 2017 Wells Fargo interviewer asked me this question. There are many many differences. Here I list my top picks. I feel c# is more like java.
- (1st word indicates the category winner)
- C++ TMP is quite an advanced art and very powerful. Java generics is useful mostly on collections and doesn’t offer equivalents to most of the TMP techniques.
- java List<Student> and List<Trade> shares a single classfile, with uniform implementation of all the methods. In c++ there are distinct object files. Most of the code is duplicated leading to code bloat, but it also supports specialization and other features.
- java generics supports extends/super. C# is even “richer”. I think c++ can achieve the same with some of the TMP tricks
- c++ supports template specialization
- C++ wins — java doesn’t allow primitive type arguments and requires inefficient boxing. C# improved on it. This is more serious than it looks because most c++ templates use primitive type arguments.
- c++ supports non-dummy-type template param, so you can put in a literal argument of “1.3”
- c++ actual type argument is available at runtime. Java erases it, but I can’t give a concrete example illustrating the effect.