javaeclipsegenericseclipse-neoneclipse-databinding

New Generics in databinding Lists causing compile errors


I am currently upgrading my RCP project to Neon and have hit the following problem.

It seems that generics have been added to the JFace databinding which has resulted in new method signatures.

Previously I was able to do

List<AbstractTestModule> modules = getModules();
IObservableList obs = Properties.selfList(AbstractTestModule.class).observe(modules);
viewer.setInput(obs);

I get a compile error because the observe method now expects List<Object>and modules cannot be automatically cast from List<AbstractTestModule> to List<Object>.

The docs are here: http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcore%2Fdatabinding%2Fproperty%2FProperties.html

Is there a way to do such a cast or is there a different strategy I could use?


Solution

  • You need to specify the generic class to use as the compiler can't infer it:

    IObservableList obs = Properties.<AbstractTestModule>selfList(AbstractTestModule.class).observe(modules);