私のDSLでは、この機能が必要です。
class Test {
val compA = dependant(true, true)(Component("parameters"))
//and this shortcut:
val compB = dependant Component("parameters")
}
どこ:
def dependant(onEnable: Boolean, onDisable: Boolean)(c: Component): Component = {
//...
}
def dependant(c: Component): Component = dependant(false, true)(c)
すべて問題ありませんが、次の構文は使用できません。
val compB = dependant Component("parameters")
それが言うので
オーバーロードされた定義へのあいまいな参照、タイプ(onEnable:Boolean、onDisable:Boolean)(c:Component)ComponentのクラスTestに依存するメソッドとタイプ(c:Component)ComponentのクラスTestに依存するメソッドの両方が期待されるタイプに一致しますか?
ただし、パラメータを括弧で囲むと、次のようになります。
val compB = dependant(Component("parameters"))
エラーはなくなりました。明らかに、コンパイラーは括弧のない場合の脱糖に失敗します。これは予想されることですか、それとも私は何か間違ったことをしていますか?これが予想される場合、なぜですか?dependant
メソッドをプレフィックスとして使用する機能を括弧なしで再利用するにはどうすればよいですか?