我想將一堆com.mongodb.DBObject對象加載到Vaadin BeanItemContainer中以在表中顯示。我遇到了構造函數從Java到Scala的轉換。如何在Scala中表達Vaadin BeanItemContainer construtor?
構造函數的定義是:
BeanItemContainer(Class<? extends BT> type)
這通過Scala編譯器:
val bic = new BeanItemContainer(Class.forName("com.mongodb.DBObject"))
然而,當我嘗試添加一個項目:
mtl.toArray.foreach {t => bic.addBean(t)}
我得到以下錯誤:
[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)}
有什麼想法/建議嗎?
UPDATE:
嘗試:
val bic: BeanItemContainer[DBObject] = new BeanItemContainer(Class.forName("com.mongodb.DBObject"))
結果:
[ERROR]com/sentientswarm/traderdashboard/UploadTradesWindow.scala:140: error: type mismatch;
found : java.lang.Class[?0(in value bic)] where type ?0(in value bic)
required: java.lang.Class[_ <: com.mongodb.DBObject]
val bic: BeanItemContainer[DBObject] = new BeanItemContainer(Class.forName("com.mongodb.DBObject"))
^
感謝, 約翰
謝謝。我忘了班級。我得出了同樣的結論,但稍微簡單一些。你可以使用:val bic = new BeanItemContainer(classOf [DBObject])。也就是說,DBObject不喜歡被告知它是一個bean,所以我最終使用了一個IndexedContainer並手動填充它。 – jxstanford 2010-12-12 20:52:35