how do I express a Vaadin BeanItemContainer construtor in Scala?


I’m trying to load a bunch of com.mongodb.DBObject objects in to a Vaadin BeanItemContainer to display in a table. I’m getting stuck on the translation of the constructor from Java to Scala.

The constructor definition is:


BeanItemContainer(Class<? extends BT> type)

This passes the scala compiler:


val bic = new BeanItemContainer(Class.forName(“com.mongodb.DBObject”))

However, when I try to add an item:


mtl.toArray.foreach {t => bic.addBean(t)}

I get the following error:

com/sentientswarm/traderdashboard/UploadTradesWindow.scala:140: error: type mismatch;
     found   : t.type (with underlying type com.mongodb.DBObject)
     required: ?0 where type ?0
                mtl.toArray.foreach {t => bic.addBean(t)}

Any thoughts/suggestions?


Try this:

val bic = new BeanItemContainer(classOf[com.mongodb.DBObject]

If you use Class.forName, the type of bic will be BeanItemContainer[_]
, not BeanItemContainer[DBObject]
. That doesn’t work with addBean because the parameter wouldn’t have a specific type.