【发布时间】:2020-09-08 08:21:30
【问题描述】:
我有以下 Java 代码,并希望将其移植到锡兰。
public interface Condition {
Condition FALSE = facts->false;
Boolean evaluate(Fact<?> fact);
default Condition and(Condition other) {
return fact -> this.evaluate(fact) && other.evaluate(fact);
}
}
@Test void test() {
String str = "A String";
Condition a = fact -> !str.empty();
Condition b = fact -> str.contains("tr");
Condition both = a.and(b);
//expect(both(Fact('fact', str)), true);
}
到目前为止,我已经尝试将alias 用于给定的代码
shared alias Condition => Boolean(Fact<out Anything>);
Condition falseCondition = (Fact<out Anything> fact) => false;
shared interface ConditionComposer {
shared formal Boolean eval(Fact<out Anything> fact);
shared default Condition and(Condition other)<--**I want to pass a Condition here for the below to work** {
return (Fact<out Anything> fact) => this.eval(fact) && other.eval(fact);
}
}
我想将Condition 作为参数传递给and(),但由于eval() 是ConditionComposer 的一部分,return 语句将无法编译。我将如何在锡兰为此编写测试用例?
【问题讨论】:
标签: ceylon