I have an interface and a class and both compile just fine. But when I try to instantiate a Separator with an anonymous implementation of Namer It fails to compile.
private interface Namer<N>
{
String getName(N o);
};
private static class Separator<H>
{
HashSet<H> oldDiff;
HashMap<String, H> newFaMap;
public Separator(HashSet<H> older, HashSet<H> newer, Namer<H> namer)
{
oldDiff = new HashSet<H> (older);
HashSet<H> newDiff = new HashSet<H> (newer);
oldDiff.removeAll(newer);
newDiff.removeAll(older);
newFaMap = makeMap(newDiff, namer);
}
private HashMap<String, H> makeMap(HashSet<H> set, Namer<H> namer)
{
HashMap<String, H> map = new HashMap<String, H>();
for (H holder : set)
{
map.put(namer.getName(holder), holder);
}
return map;
}
}
in a method
Namer<FAHolder> namer = new Namer<FAHolder>() {
public String getName(FAHolder o)
{
return o.getName();
}
};
new Separator<FAHolder>(older, newer, namer);
The compile error is:
The constructor
MyClass.Separator<FAHolder>(Set<FAHolder>, Set<FAHolder>, MyClass.Namer<FAHolder>)
is undefined
What have I overlooked?