对于这段代码(JavaFX).
StringProperty sp;
DoubleProperty dp;
StringConverter<Double> converter = new DoubleStringConverter();
Bindings.bindBidirectional(sp, dp, converter);
Run Code Online (Sandbox Code Playgroud)
我得到编译错误(在Eclipse IDE中)
这是方法签名:
public static <T> void bindBidirectional(Property<String> stringProperty, Property<T> otherProperty, StringConverter<T> converter)
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除(StringConverter)的参数化,那么我只得到警告和代码工作.
StringConverter converter = new DoubleStringConverter();
Run Code Online (Sandbox Code Playgroud)
我试图避免使用原始类型的泛型,以便我不必在我的IDE中禁止警告.
所以问题是:
编写这段代码的正确模式是什么?