Spring4D (1.2.2) TMultiMap ジェネリック クラスに苦労しています。オーバーロードされたコンストラクターを呼び出したいのですが、コンパイラーは文句を言います:
"E2250 There is no overloaded version of 'Create' that can be called with these arguments"
引数は、Spring4D ソース コードによると正しい型です。
エラーを再現する小さな何もしないプログラムを考案しました。
program Spring4DMultiMapTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Generics.Collections,
Spring.Tests.Interception.Types,
Spring.Collections.MultiMaps,
Spring.Collections;
type
TMyKey = TPair<Double, Integer>;
TMyKeyEqualityComparer = class(TInterfacedObject, IEqualityComparer<TMyKey>)
function Equals(const Left, Right: TMyKey): Boolean; reintroduce;
function GetHashCode(const Value: TMyKey): Integer; reintroduce;
end;
function TMyKeyEqualityComparer.Equals(const Left, Right: TMyKey): Boolean;
begin
if Left.Key < (Right.Key - 1E-9) then
Result := TRUE
else if Left.Key > (Right.Key + 1E-9) then
Result := FALSE
else if Left.Value < Right.Value then
Result := TRUE
else
Result := FALSE;
end;
function TMyKeyEqualityComparer.GetHashCode(const Value: TMyKey): Integer;
begin
Result := Value.Value + Round(Value.Key * 1E6);
end;
var
Events : IMultiMap<TMyKey, Integer>;
KeyComparer : IEqualityComparer<TMyKey>;
begin
KeyComparer := TMyKeyEqualityComparer.Create;
// Next line triggers error: "E2250 There is no overloaded version of 'Create' that can be called with these arguments"
Events := TMultiMap<TMyKey, Integer>.Create(KeyComparer);
end.
Spring4D ソース コードには、次の宣言があります。
TMultiMap<TKey, TValue> = class(TMultiMapBase<TKey, TValue>)
また、TMultiMap acestor が宣言されています。
TMultiMapBase<TKey, TValue> = class abstract(TMapBase<TKey, TValue>,
IMultiMap<TKey, TValue>, IReadOnlyMultiMap<TKey, TValue>)
そして、このコンストラクタがあります:
constructor Create(const keyComparer: IEqualityComparer<TKey>); overload;
これは私が呼び出したいコンストラクタです。私が理解している限り、私の引数 KeyComparer は正しい型を持っています。しかし、明らかにコンパイラは同意しません:-(
このコードを修正するには?