Can I import from multiple packages all at once in Scala?

前端 未结 1 922
遇见更好的自我
遇见更好的自我 2020-12-06 01:04

At the beginning of my Scala files in a particular project, I often have lines like these:

package com.mycompany
package subproject

import common._
import u         


        
相关标签:
1条回答
  • 2020-12-06 01:18

    You can do it easily if all imports you needed are members of some traits. If you have several traits with functions, inner classes etc. you can create object inherited from all of them. So all their stuff can be imported with simple import MyObject._. Importing class in this way became a bit tricky - you have to create a type member for each class.

    For more examples of this technique see Casbah Imports object and Scalaz object in scalaz project.

    0 讨论(0)
提交回复
热议问题