KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In Scala, is it possible for a trait to reference a named constructor argument of the class it is mixed into? The code below doesn't compile because ModuleDao's constructor argument is not a val as defined in the trait. If I add val before the constructor argument to make it public, it matches up with the one in the trait and it compiles, but I'd prefer not to set it as a val . trait Daoisms { val sessionFactory:SessionFactory protected def session = sessionFactory.getCurrentSession } class ModuleDao(sessionFactory:SessionFactory) extends Daoisms { def save(module:Module) = session.saveOrUpdate(module) } /* Compiler error: class ModuleDao needs to be abstract, since value sessionFactory in trait Daoisms of type org.hibernate.SessionFactory is not defined */ // This works though // class ModuleDao(val sessionFactory:SessionFactory) extends Daoisms { ... }
Tags (comma-separated)
Save Edits
Cancel