【问题标题】:How to import class from other directory in scala?如何从scala中的其他目录导入类?
【发布时间】:2022-01-21 12:20:12
【问题描述】:

我需要使用 PriceAlert 类中的 UIController 类,但这是不可能的,即使它们在同一个包中:co.uproot.abandon。 问题是我可以在 UIController 类中使用 PriceAlert 类,但反过来不行。

files layout

【问题讨论】:

  • 如果您需要使用其他地方的控制器类,这可能是设计不佳的标志。将代码拆分成模块以防止此类导入是一件好事。

标签: scala import package sbt


【解决方案1】:

在您的根目录build.sbt 中查找dependence of modulesgui 可能依赖于 base,因此您可以使用 PriceAlert from base inside UIController from UIController

如果你需要相互使用来自不同模块的类,那么这意味着你有模块的循环依赖

sbt: cyclic dependence between modules?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-31
    • 2014-09-07
    • 2017-07-31
    • 1970-01-01
    • 2013-07-26
    • 2017-08-20
    • 2016-12-03
    • 1970-01-01
    相关资源
    最近更新 更多