Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Design Patterns
Expertise: Beginner
May 31, 1998

Templates in java

Question:
Any suggestions on a good way to implement templates in java?

Answer:
The normal way to implement template behavior in Java is to create an interface defining the common behavior that is being abstracted. Every class that would normally would be instantiated as a template in C++, would have to implement this interface in Java. A good example of this is the java.lang.Comparable interface in JDK 1.2. You can write a single sort method to sort any object implementing the Comparable interface, rather than writing N different sorts. However, you will find that this approach is not sufficient to achieve all of the benefits of C++ templates. You may consider doing a search on the web for an experimental Java compiler called Pizza, which implements extra functionality like templates.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap