鉴于其扩展一个类的两个对象:如何在函数中将对象作为Scala中的参数传递?
object PageDAO
extends SalatDAO[Page, Long](collection=Config.getMongoDB("db_development")("pages"))
object BookDAO
extends SalatDAO[Book, Long](collection=Config.getMongoDB("db_development")("books"))
我想写它具有对象作为参数的函数:
def find[ID](salatDAO:SalatDAO[Product,ID]) = salatDAO.find(MongoDBObject()).limit(10)
像
scala> find[Long](PageDAO)
<console>:27: error: type mismatch;
found : PageDAO.type (with underlying type object PageDAO)
required: com.novus.salat.dao.SalatDAO[Product,Long]
Note: Page <: Product (and PageDAO.type <: com.novus.salat.dao.SalatDAO[Page,Long]), but class SalatDAO is invariant in type ObjectType.
You may wish to define ObjectType as +ObjectType instead. (SLS 4.5)
find[Long](PageDAO)
这可能吗?
您是否尝试过的编译器的顶端? – sschaef
我不明白编译器提示的实际含义。我在哪里附加+ ObjectType?作为SalatDAO定义的一部分? –