我们有一个项目,其中包含使用hocon配置构建的大型配置文件.有意在可能的情况下使用变量来创建template_section,并根据某些选项在模板中设置一些值.
问题是variables在这个配置中使用时,我必须始终引用绝对路径.有可能以某种方式使用规范名称(如果属性位于同一级别)?
例:
foo {
bar = 4
baz = ${foo.bar} // work perfect
baz = ${[this].bar} // can I do smth like that? Any ideas.
}
Run Code Online (Sandbox Code Playgroud)
更真实的例子.我实际上正在寻找的是建立hocon配置的一般OOP能力.我有一些父配置template_config与important_option内部真正取决于实现:
custom_config1或者custom_config2,我有什么现在做的是落实important_option在儿童的配置,因为绝对pathes我不得不提及自定义配置sectsions名.
custom_config1: $template_config {
child_option = child_value1
}
custom_config2: $template_config {
child_option = child_value2
}
template_config {
important_option = ${child_option} // NOT POSSIBLE
child_option = not_implemented
}
Run Code Online (Sandbox Code Playgroud) sbt 项目中有两个完整的构建定义文件:Build.scala和Helpers.scala. 它们位于project文件夹中。
我想将Helpers模块放入单独的子文件夹中project/utils。当我这样做时import utils.Helpers,Build.scala它说:
未找到:
object utils
是否可以在 sbt 完整构建定义中定义遵循包的目录结构?
class A {
def p = 18
def out() {
println(p)
}
}
class B extends A {
def p = 21
}
new B().out()
Run Code Online (Sandbox Code Playgroud)
我有上面的片段。输出是****..你猜怎么着?
我的问题是 - 我怎样才能像在 Java 中那样获得结果?
ps:groovy 控制台适用于那些想要执行上述示例的人:groovyconsole.appspot.com
UPD: 将属性转换为方法解决了问题。还有其他选择吗?
使用Akka Streams读取CSV文件 - 基于此问题.我使用Akka Streams读取CSV.现在我需要逐行执行它 - 但我还需要知道标题的名称是什么.任何选择?
UPD.澄清一点.
FileIO.fromPath(Paths.get("a.csv))
.via(Framing.delimiter(ByteString("\n"), 256, true).map(_.utf8String))
.runForeach(println /* header + current line for each line*/)
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释对象行为的模式匹配.同一类的两个对象是否相同?
object Solution extends App {
case class EE() { }
object EE1 extends EE
object EE2 extends EE
val k: EE = EE1
println(k.getClass) // class Solution$EE1$
println(k.isInstanceOf[EE2.type]) // returns FALSE
println(k.getClass.isInstanceOf[EE2.type.getClass]) // returns FALSE
k match {
case EE2 => println("EE1 match EE2!!!") // MATCH THIS LINE/// WHY???
case EE1 => println("EE1 match EE1. OK!")
}
}
Run Code Online (Sandbox Code Playgroud)