私はクラスで内部的に使用する比較的複雑なジェネリックタイプ(たとえばMap<Long,Map<Integer,String>>
)を持っています。 (外部の可視性はなく、実装の詳細です)。これをtypedefで非表示にしたいのですが、Javaにはそのような機能はありません。"疑似typedef反パターン"の正当な理由はありますか?
昨日私は次のイディオムを再発見し、それがconsidered an anti-patternであることに失望しました。
class MyClass
{
/* "Pseudo typedef" */
private static class FooBarMap extends HashMap<Long,Map<Integer,String>> { };
FooBarMap[] maps;
public FooBarMap getMapForType(int type)
{
// Actual code might be more complicated than this
return maps[type];
}
public String getDescription(int type, long fooId, int barId)
{
FooBarMap map = getMapForType(type);
return map.get(fooId).get(barId);
}
/* rest of code */
}
は、これまでのタイプが隠されていると(私の読書でそれを使用するゲッツの主な反論である)ライブラリAPIの一部を形成していない。このため任意の正当性があることはできますか?
ジェネリック型は複雑ですか?ハ!私が幼い頃、朝3時に再帰的に入れ子になった6つのジェネリック薬を扱うことになった。 –
靴なし...上り坂...雪の中。 – skaffman
@Marcus Downing :そして、再帰の終わりにレストランで朝食を食べるのは第七レベルです。 ;-) – Mnementh