Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Generics and APIs

The following tutorial does a good job a pointing out some pitfalls that one needs to avoid when converting an API to use generics (see section 20). It's brief, which I think is a good indication that there's not too many land mines to avoid, but there's definitely one or two you can easily step on if you're not careful.

http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

John

At 04:48 PM 4/10/2008, Mike Kucera wrote:
Java implements generics through erasure, meaning the resulting bytecode is
exactly the same as if you didn't use generics at all.

In fact I would argue that its not really an API change at all. The
contract of the existing API (documented or not) is that it returns a Map
from Strings to ILanguageDescriptor[], and clients expect that to be true,
the addition of generics just makes the compiler aware of that
postcondition so that can check it for you.

Mike Kucera
Software Developer
IBM CDT Team, Toronto
mkucera@xxxxxxxxxx




             Jason
             Montojo/Toronto/I
             BM@IBMCA                                                   To
             Sent by:                  cdt-dev@xxxxxxxxxxx
             cdt-dev-bounces@e                                          cc
             clipse.org
                                                                   Subject
                                       [cdt-dev] Generics and APIs
             04/10/2008 03:38
             PM


             Please respond to
               "CDT General
             developers list."
             <cdt-dev@eclipse.
                   org>







Hi everyone,

I've been fixing compiler warnings about generics in the language mapping
classes.  This involved having to change a number of method signatures to
account for parameterized collections. For example, I changed this in
LanguageManager:

Old:
public Map getContentTypeIdToLanguageDescriptionsMap(){ ... }

New:
public Map<String, ILanguageDescriptor[]>
getContentTypeIdToLanguageDescriptionsMap(){ ... }

Such a change wouldn't break existing clients and it makes the API much
easier to work with.  Regardless, it is still an API change.

Should I go ahead and make the changes to the signatures?  Or should I
leave them as-is?  I know we're already past the API freeze so I'd like to
know how the community feels about this.

Thanks,
Jason Montojo
IBM CDT Team
IBM Toronto Lab
905-413-5228
jmontojo@xxxxxxxxxx

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top