Same Type Inference 2x...One Compiles, One Does Not.
Sorry, wrong forum on first post:
Consider:
publicinterface Graph<T>extends ReadOnlyGraph<T>, WriteOnlyGraph<T>
{
}
publicinterface Vertex<T>
{
public T getContents();
}
publicclass DefaultGraphFactoryimplements GraphFactory
{
private GraphFactory _factory = AdjacencyHashFactory.Singleton;
publicstaticfinal DefaultGraphFactory Singleton =new DefaultGraphFactory();
private DefaultGraphFactory()
{
}
public <T> Graph<T> makeGraph()
{
return _factory.makeGraph();
}
}
publicclass DefaultSetFactoryimplements SetFactory
{
private SetFactory _factory = HashSetFactory.Singleton;
publicstaticfinal DefaultSetFactory Singleton =new DefaultSetFactory();
private DefaultSetFactory()
{
}
public <T> Set<T> makeSet()
{
return _factory.makeSet();
}
}
and the usage:
publicclass ScopeGraph<K,V>
{
Graph<Set><K>> _scopes;
Vertex<Set><K>> _currentScope =null;
public ScopeGraph()
{
_scopes = DefaultGraphFactory.Singleton.makeGraph();
_currentScope = DefaultSetFactory.Singleton.makeSet();// comment me to compile clean
}
...
}
This seems like 2 applications of the same pattern. I don't understand why the compiler can infer the correct type for the _scope assignment but not _currentScope. Error is:
incompatible types; no instance(s) of type variable(s) T exist so that java.util.Set<T> conforms to com.continental.datastructures.graph.Vertex<java.util.Set><K>>
found : <T>java.util.Set<T>
required: com.continental.datastructures.graph.Vertex<java.util.Set><K>>

