Scala无法解析构造函数

时间:2017-01-23 16:26:03

标签: java scala constructor

我正在利用Scala和Java之间的互操作性,并使用以下使用Scala的代码来实例化用Java编写的同一个项目中的类。 CommandExecutor参数继承自父类。

class IdmIdentityServiceImpl extends ServiceImpl with IdmIdentityService {
    override def createNativeUserQuery: NativeUserQuery = {
        new NativeUserQueryImpl(commandExecutor)
      }
}

我在实例化NativeUserQueryImpl cannot resolve constructor

时遇到错误

NativeUserQueryImpl是用Java编写的,但我一直在阅读Java和Scala之间的互操作性,感觉它应该可行。

这是NativeUserQueryImpl类,它在其中一个构造函数中接受CommandExecutor类型。该类来自可流动引擎库。

public class NativeUserQueryImpl extends AbstractNativeQuery<NativeUserQuery, User> implements NativeUserQuery {

  private static final long serialVersionUID = 1L;

  public NativeUserQueryImpl(CommandContext commandContext) {
    super(commandContext);
  }

  public NativeUserQueryImpl(CommandExecutor commandExecutor) {
    super(commandExecutor);
  }

  // results ////////////////////////////////////////////////////////////////

  public List<User> executeList(CommandContext commandContext, Map<String, Object> parameterMap, int firstResult, int maxResults) {
    return commandContext.getUserEntityManager().findUsersByNativeQuery(parameterMap, firstResult, maxResults);
  }

  public long executeCount(CommandContext commandContext, Map<String, Object> parameterMap) {
    return commandContext.getUserEntityManager().findUserCountByNativeQuery(parameterMap);
  }

}

编辑:

完整错误

Error:(31, 5) overloaded method constructor NativeUserQueryImpl with alternatives:
  (x$1: org.flowable.idm.engine.impl.interceptor.CommandExecutor)org.flowable.idm.engine.impl.NativeUserQueryImpl <and>
  (x$1: org.flowable.idm.engine.impl.interceptor.CommandContext)org.flowable.idm.engine.impl.NativeUserQueryImpl
 cannot be applied to (org.flowable.engine.impl.interceptor.CommandExecutor)
    new NativeUserQueryImpl(commandExecutor)

1 个答案:

答案 0 :(得分:1)

从原始问题中发布的完整错误看来,从父类CommandExecutor继承的ServiceImpl在库中有两个不同的版本

org.flowable.idm.engine.impl.interceptor.CommandExecutororg.flowable.engine.impl.interceptor.CommandExecutor其中微妙的区别在于,一个来自idm包,一个不是。

将ServiceImpl从第二个包更改为第一个包,更新传入的CommandExecutor参数,并修复问题。

相关问题