<tfoot id='KfjuT'></tfoot>
    <legend id='KfjuT'><style id='KfjuT'><dir id='KfjuT'><q id='KfjuT'></q></dir></style></legend>
    • <bdo id='KfjuT'></bdo><ul id='KfjuT'></ul>

      <small id='KfjuT'></small><noframes id='KfjuT'>

        <i id='KfjuT'><tr id='KfjuT'><dt id='KfjuT'><q id='KfjuT'><span id='KfjuT'><b id='KfjuT'><form id='KfjuT'><ins id='KfjuT'></ins><ul id='KfjuT'></ul><sub id='KfjuT'></sub></form><legend id='KfjuT'></legend><bdo id='KfjuT'><pre id='KfjuT'><center id='KfjuT'></center></pre></bdo></b><th id='KfjuT'></th></span></q></dt></tr></i><div id='KfjuT'><tfoot id='KfjuT'></tfoot><dl id='KfjuT'><fieldset id='KfjuT'></fieldset></dl></div>
      1. 使用 Scala 的 Raw 类型实现 Java 接口

        时间:2024-05-09

        <tfoot id='vgyv2'></tfoot>

          1. <i id='vgyv2'><tr id='vgyv2'><dt id='vgyv2'><q id='vgyv2'><span id='vgyv2'><b id='vgyv2'><form id='vgyv2'><ins id='vgyv2'></ins><ul id='vgyv2'></ul><sub id='vgyv2'></sub></form><legend id='vgyv2'></legend><bdo id='vgyv2'><pre id='vgyv2'><center id='vgyv2'></center></pre></bdo></b><th id='vgyv2'></th></span></q></dt></tr></i><div id='vgyv2'><tfoot id='vgyv2'></tfoot><dl id='vgyv2'><fieldset id='vgyv2'></fieldset></dl></div>
          2. <small id='vgyv2'></small><noframes id='vgyv2'>

              <tbody id='vgyv2'></tbody>

                <bdo id='vgyv2'></bdo><ul id='vgyv2'></ul>
                <legend id='vgyv2'><style id='vgyv2'><dir id='vgyv2'><q id='vgyv2'></q></dir></style></legend>
                1. 本文介绍了使用 Scala 的 Raw 类型实现 Java 接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Scala 为 Sonar 构建扩展.我需要扩展以下Java接口:

                  I'm trying to build an extension for Sonar, using Scala. I need to extend the following Java interface:

                  public interface Decorator extends BatchExtension, CheckProject {
                      void decorate(Resource resource, DecoratorContext context);
                  }
                  

                  Resource 类型实际上是这样定义的:

                  but Resource type is actually defined like:

                  public abstract class Resource<PARENT extends Resource>
                  

                  我知道我可以解决创建 Java 原始超类的问题.我想坚持仅使用 Scala,也知道是否有我遗漏的解决方案,以及我是否可以建议 SonarSource 人员在他们这边做出改进(使用原始类型).

                  I know I can workaround creating a Java raw super-class. I'd like to stick to Scala-only, also know if there's a solution I'm missing, and whether there's an improvement I could suggest to SonarSource people to make on their side (on using raw types).

                  我已经阅读了这方面的问题,以及某些情况下的一些解决方法,但似乎没有一个适用于这里(一种解决方法,一张明显固定的票,还有一张 2091 的票……)

                  I've read there were issues with this, and some workarounds for some cases, but none seemed to apply here (a workaround, an apparently fixed ticket, also there's ticket 2091...)

                  推荐答案

                  经过反复试验并查看错误消息,我想出了这个编译:

                  After some trial and error and looking at the error messages, I came up with this which compiles:

                  import org.sonar.api.batch._
                  import org.sonar.api.resources._ 
                  
                  object D {
                    type R = Resource[T] forSome {type T <: Resource[_ <: AnyRef]}
                    type S[T] = Resource[T] forSome {type T <: Resource[_ <: AnyRef]}
                  }
                  
                  class D extends Decorator {
                    def decorate(r: D.R, context: DecoratorContext) {}
                    //def decorate(r: D.S[_], context: DecoratorContext) {} // compiles too
                    def shouldExecuteOnProject(project: Project) = true
                  }
                  

                  我不确定它是否能让您实现所需的功能.我查看了 Resource,它可以代表File 扩展 Resource<Directory> 或有时是擦除(原始?)类型,仅扩展 Resource 就像 Directory.

                  I'm not sure whether it will allow you to implement what you need. I looked at Resource, and it could represent File which extends Resource<Directory> or sometimes be an erased (raw?) type that just extends Resource like for Directory.

                  再想一想,forSome 可以消除 - 这也可以编译:

                  thinking about it some more, the forSome can be eliminated - this compiles too:

                  def decorate(resource: Resource[_ <: Resource[_ <: AnyRef]],
                               context: DecoratorContext) {
                  }
                  

                  这篇关于使用 Scala 的 Raw 类型实现 Java 接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <tfoot id='wd0FR'></tfoot>
                  <legend id='wd0FR'><style id='wd0FR'><dir id='wd0FR'><q id='wd0FR'></q></dir></style></legend>
                  <i id='wd0FR'><tr id='wd0FR'><dt id='wd0FR'><q id='wd0FR'><span id='wd0FR'><b id='wd0FR'><form id='wd0FR'><ins id='wd0FR'></ins><ul id='wd0FR'></ul><sub id='wd0FR'></sub></form><legend id='wd0FR'></legend><bdo id='wd0FR'><pre id='wd0FR'><center id='wd0FR'></center></pre></bdo></b><th id='wd0FR'></th></span></q></dt></tr></i><div id='wd0FR'><tfoot id='wd0FR'></tfoot><dl id='wd0FR'><fieldset id='wd0FR'></fieldset></dl></div>

                    1. <small id='wd0FR'></small><noframes id='wd0FR'>

                        <tbody id='wd0FR'></tbody>
                        • <bdo id='wd0FR'></bdo><ul id='wd0FR'></ul>