Forum Stats

  • 3,853,730 Users
  • 2,264,259 Discussions
  • 7,905,436 Comments

Discussions

can you do the Java equivalent of this with Generics?

843793
843793 Member Posts: 41,732 Green Ribbon
edited May 9, 2003 8:47AM in Generics
hi,

http://www.informit.com/content/index.asp?product_id=%7B4BCD9193-97E4-4004-AF84-D7346E261C69%7D

thanks,
asjf

Comments

  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    No, and in my opinion that is to Java's benefit.
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    No, and in my opinion that is to Java's benefit.
    I agree :)

    Are Java generics more selective over what they can be parameterized on in that case?

    I had thought that C++ templates were parameterized on class types but seemingly not?

    thanks,
    asjf

  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    There is no "specialization" in Java's generic system.
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    There is no "specialization" in Java's generic system.
    thanks - I'm not new to java but am new to generics and have not heard of "specialization"?

    is this related to extending a class?


  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    Think of specialization as "compile-time" polymorphism. It allows you to create different implementations of methods/classes for different types, selected at compile-time. For example, I use template specialization extensively in Jace to unify entire sets of type-disparate JNI functions.

    Specialization is a very powerful technique and is also used extensively in template meta-programming (which brings us back to the OP). Even were the current form of Java generics to somehow magically support some form of specialization, you still wouldn't be able to perform meta-programming as Java generics don't work with constants.

    Any surface similarities between Java generics and C++ templates expire at trivial inspection, which means that it's a fairly futile exercise to try to compare the two.

    God bless,
    -Toby Reyelts

    Check out the free, open-source, JNI toolkit - Jace, http://jace.reyelts.com/jace
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    I had thought that C++ templates were parameterized on class types but seemingly not?
    Indeed, constant non-class typed values work too. They can be used for example to define dimensions.

This discussion has been closed.