我正在尝试使用Scala为Sonar构建扩展.我需要扩展以下Java接口:
public interface Decorator extends BatchExtension, CheckProject {
void decorate(Resource resource, DecoratorContext context);
}
Run Code Online (Sandbox Code Playgroud)
但资源类型实际上定义如下:
public abstract class Resource<PARENT extends Resource>
Run Code Online (Sandbox Code Playgroud)
我知道我可以解决创建Java原始超类的问题.我想坚持只使用Scala,也知道是否有一个我缺少的解决方案,以及是否有一个改进我可以建议SonarSource人员在他们身边(使用原始类型).
我已经阅读过这方面存在的问题,以及某些情况下的一些解决方法,但似乎没有适用于此处(一种解决方法,一张明显固定的机票,还有2091号机票...)
以下代码使用Sonar + FindBugs引发"未经检查/未确认的强制转换"严重违规:
1 public static <P extends ComponentContainer & AlignmentHandler> void addComponentAligned(P parent, Component child, Alignment alignment) {
2 parent.addComponent(child);
3 parent.setComponentAlignment(child, alignment);
4 }
Run Code Online (Sandbox Code Playgroud)
我应该如何避免这种违规?
编辑:违规行为在第3行
编辑:方法签名如下:ComponentContainer#addComponent(Component)AlignmentHandler #setComponentAlignment(Component,Alignment)