我正在尝试将 a 绑定TextField.textProperty()
到ObjectProperty<LocalDateTime>
自定义控件中的 a 。以下代码在 Eclipse 中编译并运行:
package main.java
import java.time.LocalDateTime;
import org.reactfx.value.Var;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleStringProperty;
public class Playbook {
public void bindTimeString(final ObjectProperty<LocalDateTime> timepoint, final SimpleStringProperty textProperty) {
Var.mapBidirectional(textProperty, s -> LocalDateTime.now(), t -> "").bindBidirectional(timepoint);
}
}
但是,当我使用 maven 构建应用程序时,出现编译错误:
javac -classpath reactfx-2.0-M5.jar Playbook.java
Playbook.java:12: error: no suitable method found for bindBidirectional(ObjectProperty<LocalDateTime>)
Var.mapBidirectional(textProperty, s -> LocalDateTime.now(), t -> "").bindBidirectional(timepoint);
^
method Property.bindBidirectional(Property<Object>) is not applicable
(argument mismatch; ObjectProperty<LocalDateTime> cannot be converted to Property<Object>)
method Var.bindBidirectional(Property<Object>) is not applicable
(argument mismatch; ObjectProperty<LocalDateTime> cannot be converted to Property<Object>)
1 error
一种解决方法是声明一个临时Var<LocalDateTime
保存mapBidirectional
结果,然后绑定它。
public void bindTimeString(final ObjectProperty<LocalDateTime> timepoint, final SimpleStringProperty textProperty) {
final Var<LocalDateTime> v = Var.mapBidirectional(textProperty, s -> LocalDateTime.now(), t -> "");
v.bindBidirectional(timepoint);
}
使用 Eclipse 编译,并按预期从命令行使用 maven 编译。
感觉就像类型推断实现中的编译器错误,但我不是 Java 语言规范的专家。我希望可以从 lambda 返回值中推断出类型。无论如何,无论是 Eclipse 的 java 编译器还是 JDK 编译器都是错误的。