在Scala中实现具有原始类型的方法 [英] Implementing methods having raw types in Scala

查看:111
本文介绍了在Scala中实现具有原始类型的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Scala中使用Drools Planner(用Java编写)时遇到了问题。 Drools规划器中的一个接口声明为:

I have a problem in using Drools Planner (written in Java) in Scala. One of interfaces in Drools planner is declared as:

public interface Score<S extends Score> extends Comparable<S>

然而,另一个界面使用得分作为原始类型:

However another interface uses 'Score' as a raw type:

public interface Solution {
    Score getScore();

然后我想在Scala中实现这个接口:

Then I'd like to implement this interface in Scala:

class MySolution extends Solution {
    def getScore: Score = ...

我收到编译错误:Scala编译器不允许写'def getScore:Score'。当我尝试添加'Score [_]'或'Score [whatever]'编译器抱怨类型不兼容时。我该怎么办?

And I get a compilation error: Scala compiler disallows writing just 'def getScore: Score'. When I try adding 'Score[_]' or 'Score[whatever]' compiler complains about type incompatibility. What should I do?

推荐答案

Drools Planner (5.2.0.M2)解决此问题
这是git上的提交。

The next release of Drools Planner (5.2.0.M2) will fix this issue. Here's the commit on git.

在某些情况下,人们希望定义自己的得分实施(例如 NurseRosterScore 实现 HardAndSoftScore ),以便能够根据硬约束类型或软约束类型向用户显示最佳解决方案中究竟违反的内容。这一改变是使这更容易和更清洁的第一步(即使它已经可行)。

In some cases, people want to define their own Score implementation (for example NurseRosterScore implements HardAndSoftScore), to be able to show to the user per hard or soft constraint type what exactly is violated in the best solution. This change is the first step to make that easier and cleaner (even though it's already possible).

这篇关于在Scala中实现具有原始类型的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆