Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 481 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What are the differences between Generics in C# and Java... and Templates in C++?

#1
I mostly use Java and generics are relatively new. I keep reading that Java made the wrong decision or that .NET has better implementations etc. etc.

So, what are the main differences between C++, C#, Java in generics? Pros/cons of each?
Reply

#2
Wikipedia has great write-ups comparing both [Java/C# generics][1] and [Java generics/C++][2] templates. The [main article on Generics][3] seems a bit cluttered but it does have some good info in it.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply

#3
Anders Hejlsberg himself described the differences here "[Generics in C#, Java, and C++][1]".


[1]:

[To see links please register here]

Reply

#4
The biggest complaint is type erasure. In that, generics are not enforced at runtime. [Here's a link to some Sun docs on the subject][1].

> Generics are implemented by type
> erasure: generic type information is
> present only at compile time, after
> which it is erased by the compiler.


[1]:

[To see links please register here]

Reply

#5
C++ templates are actually much more powerful than their C# and Java counterparts as they are evaluated at compile time and support specialization. This allows for Template Meta-Programming and makes the C++ compiler equivalent to a Turing machine (i.e. during the compilation process you can compute anything that is computable with a Turing machine).
Reply

#6
In Java, generics are compiler level only, so you get:

a = new ArrayList<String>()
a.getClass() => ArrayList

Note that the type of 'a' is an array list, not a list of strings. So the type of a list of bananas would equal() a list of monkeys.

So to speak.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through