S
sarathy
Hi all,
Is there any relation between the J2se 5.0 generics and
C++ templates ??
Regards,
Sarathy
Is there any relation between the J2se 5.0 generics and
C++ templates ??
Regards,
Sarathy
sarathy said:Is there any relation between the J2se 5.0 generics and
C++ templates ??
Darryl said:Not really, no, except in concept.
EJP said:Not really, no, except in *syntax*.
C++ templates are a code-generation mechanism.
Java Generics are a type-constraint system which generate no code at
all.
sarathy said:Is there any relation between the J2se 5.0 generics and
C++ templates ??
Michael Redlich said:The C++ templates mechanism is considered generic programming, so based
on that alone, I would have to say "yes" to your question, assuming of
course, that the relation between generics in C++ and Java is purely
based on concept.
I totally agree with everyone else that the implementation of generics
in both languages is vastly different.
Darryl said:Which is implementation, and why I said "in concept".
But both work on the same basic concept: providing a mechanism for
writing code in a generic way and allowing a developer to specify the
desired functionality at compile-time.
EJP said:Darryl L. Pierce wrote:
Doesn't leave much. I agree that they both provide mechanisms for
writing code in a type-generic way.
Mark said:So: type generic code, and angle brackets. That's it?
EJP said:I think so, and to be honest I wish Java didn't have the angle brackets.
EJP said:I think so, and to be honest I wish Java didn't have the angle brackets.
At least the Java parser understands that << doesn't /always/ mean "right
shift"...
Chris said:BTW, I think you are over-stating the similarity between Java's generics and
C++'s templates.
Yes.EJP said:Overstating?
'type-generic code' (not my term): wasn't that far enough?
Michael said:Yes.
everybody else thought I was understating! I got it down to
Java Generics do not support specializations nor do they support
parametrization of non-types. These two key features lead C++ templates
to greatly differ from Java generics.
Overstating? everybody else thought I was understating! I got it down to
'type-generic code' (not my term): wasn't that far enough?
Not really, no, except in *syntax*.
C++ templates are a code-generation mechanism. Java Generics are a
type-constraint system which generate no code at all.
EJP said:I think it's more than just implementation actually. C++ templates are
*conceptually* associated with the idea of 'instantiation' per type.
Darryl said:And, as you said, C++ templates generate new code. Java generics do not.
That's an implementation detail that completely separates the two
otherwise conceptual similar systems.
EJP said:Code generation is carried out for and only for the purpose of template
instantiation,
Darryl said:Does the template specification say that that is what templates are
intended to do? Or is it simply the mechanism for fulfilling the
specification?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.