【问题标题】:cannot access '<init>': it is public /*package*/ in 'Constructor'无法访问“<init>”:它在“构造函数”中是公共的 /*package*/
【发布时间】:2019-12-27 09:18:10
【问题描述】:

我正在尝试在 this tutorial 之后使用 SnakeYAML 解析 Kotlin 中的 yaml:

data class Case(val args: List<String>, val expected: String, val score: Int)
data class TestCases(val target: String, val cases: List<Case>)

val yaml = Yaml(Constructor(TestCases::class.java))

但代码在 IntelliJ 中返回这些错误

无法访问'':它是public/*package*/ in 'Constructor'

用于使用Constructor,如java.lang.reflect.Constructor,以及

以下函数都不能使用提供的参数调用:

  • 在 org.yaml.snakeyaml.Yaml 中定义的公共构造函数 Yaml(dumperOptions: DumperOptions!)
  • 在 org.yaml.snakeyaml.Yaml 中定义的公共构造函数 Yaml(loadingConfig: LoaderOptions!)
  • 在 org.yaml.snakeyaml.Yaml 中定义的公共构造函数 Yaml(constructor: BaseConstructor!)
  • 在 org.yaml.snakeyaml.Yaml 中定义的公共构造函数 Yaml(representer: Representer!)

使用Yaml 就像在org.yaml.snakeyaml.Yaml 中一样,我认为这是期待来自ConstructorBaseConstructor

我该如何解决这个问题?谢谢。

【问题讨论】:

    标签: kotlin reflection yaml


    【解决方案1】:

    我猜你正在导入错误的类。应该是org.yaml.snakeyaml.constructor.Constructor 而不是java.lang.reflect.Constructor

    【讨论】:

      猜你喜欢
      • 2015-02-11
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      相关资源
      最近更新 更多