Package contains object and package with same name

前端 未结 2 1691
花落未央
花落未央 2021-01-05 00:32

I am having problems compiling some Scala with Maven or Eclipse where I try to import a class from a Java jar which contains both a namespace and class of the same name.

相关标签:
2条回答
  • 2021-01-05 00:56

    The actual compiler option is "-Yresolve-term-conflict:strategy" where strategy is either package, object, error.

    0 讨论(0)
  • 2021-01-05 01:00

    That kind of limitation was outlined in SI-4695: package object misbehaves in the presence of classfiles.

    As suggested in SI-2089 (naming restriction makes some jars unusable), you could try and use the "resolve-term-conflict", as implemented in changeset 25145:

    Added a -Y option to resolve namespace collisions between package and object.
    It's a blunt instrument: if people have lots of these conflicts they need to resolve in individually nuanced fashion, they'll probably remain out of luck.

    val termConflict  = ChoiceSetting     ("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", 113 List("package", "object", "error"), "error")
    
    // Some jars (often, obfuscated ones) include a package and
    // object with the same name. Rather than render them unusable,
    // offer a setting to resolve the conflict one way or the other.
    // This was motivated by the desire to use YourKit probes, which
    // require `yjp.jar` at runtime. See SI-2089.
    
    0 讨论(0)
提交回复
热议问题