Java Generics with legacy code (I)
11 January 2008In this post, I will write about how Java generics help us in using legacy code.
Generics are new in Java and now developers understand the importance of it and it is being used as required. Question arises, what about the legacy code? Consider an IT firm that is working on an application for 5 years, and they used Java 1.4 for development. They the plan to use 1.5 for development simply because it is better than 1.4. Are they supposed to convert the old code to 1.5 also? This is not practical, as it requires a lot of efforts and time. We may use older code with generics but definitely there will be some warnings. Lets take an example:
Legacy code:
public interface University { public void setStudents(Collection c); public Collection getStrudents(); } public class UniImpl implements University{ private Collection students; public UniImpl(){ students = new ArrayList(); } public Collection getStudents() { return students; } public void setStudents(Collection c) { this.students = c; } }
In the next part, I will give an example how to make the above code generic.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Java Generics with legacy code (I)