PDA

View Full Version : inconsistent use of generics



aberezin
4 May 2008, 9:48 AM
I just started playing with gxt and it seems really nicely designed. However, there seems to be some inconsistency in how generics are used. It is easiest to see by example. The API has this:



ContentProvider<I> declares inputChanged (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/ContentProvider.html#inputChanged%28com.extjs.gxt.ui.client.viewer.Viewer,%20I,%20I%29)(Viewer (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/Viewer.html) viewer, I (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/ContentProvider.html) oldInput, I (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/ContentProvider.html) newInput)



This issue is that it is using the raw declaration of Viewer. It would be better to do this:


ContentProvider<I, V> declares inputChanged (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/ContentProvider.html#inputChanged%28com.extjs.gxt.ui.client.viewer.Viewer,%20I,%20I%29)(Viewer<V> (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/Viewer.html) viewer, I (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/ContentProvider.html) oldInput, I (file:///C:/_di/eclipse/workspace/gxt-1.0-beta2/docs/api/com/extjs/gxt/ui/client/viewer/ContentProvider.html) newInput)

The reason, beyond the obvious desire to pass on the type to the Viewer declaration, is kinda subtle. Consider this:


class FooContentProvider<I> implements ContentProvider<I> {
public void inputChanged(Viewer viewer, I oldInput, I newInput) {
// doStuff
}
}

In our project, this generate an eclipse compile error because we have errors (not warnings) for use of the raw type. So lets do this:


class FooContentProvider<I,V> implements ContentProvider<I> {
public void inputChanged(Viewer<V> viewer, I oldInput, I newInput) {
// doStuff
}
}

That doesnt work though. We get an eclipse compile:

The method inputChanged(Viewer<V>, I, I) of type FooContentProvider<I,V> has the same erasure as inputChanged(Viewer, I, I) of type ContentProvider<I> but does not override it