• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

C++ Templates and java Generics

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off this is not a troll posting. I'm a C++ programmer who needs to write some test Java code to test our system's ability to reverse engineer and round-trip Java 1.5 code - in this case generics. I'll try and keep this as brief as possible by using very cut down examples.

In C++ I can do this:

template<typename T> class Foo
{
public:
T *theT;
Foo()
{
theT = new T(); // Create an instance of whatever type T is
}
};

Can I / How do I - do the same kind of thing using Java Generics?

Many thanks for your time.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you can't do this.

There's a really nice article comparing C++ templates and Java generics in the current (July 2004) issue of C/C++ User's Journal -- worth grabbing a copy if you can.
 
reply
    Bookmark Topic Watch Topic
  • New Topic