Why can't a class extend traits with method of the same signature?

后端 未结 5 2151
旧时难觅i
旧时难觅i 2020-12-23 12:02

Why do I get the error below? How to workaround it?

I assumed that since A and B compile to (interface,class) pairs, it\'s a matter of choosing the right static meth

5条回答
  •  抹茶落季
    2020-12-23 12:46

    I had the same problem and I didn't like to have to create an intermediary trait because I can have 4,5 or even 6 traits with the same methods, because it is traits containing CRUD operations (find, create...). Furthermore I needed to use those trait together only for test purpose and I always try to avoid as much as possible to modify the structure of my project only to make my test easier. So I simply implemented those traits in different objects :

    class somethingToTest {
      object AImpl extends ATrait 
      object BImpl extends BTrait
    
      val a = AImpl.methodDuplicated()
      val b = BImpl.methodDuplicated()
    }
    

    It is probably not the most clever way to use traits but it doesn't require any change in the project's code, it only implies to have a bit more code in the tests.

提交回复
热议问题