Seemingly Identical Inference Case Infered in One Spot, but Not Other

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>>

[3486 byte] By [DejasPerPera] at [2007-11-27 4:49:41]
# 1
I don't have the answer to your original question, but I just wanted to point out that your WriteOnlyGraph is as funny as my WOM! http://en.wikipedia.org/wiki/Write_Only_Memory
Dalzhima at 2007-7-12 10:02:49 > top of Java-index,Java Essentials,Java Programming...
# 2
makeSet() returns a Set<T>, but you're assigning it to a Vertex<Set<T>>. Looks like either makeSet() or _currentScope is declared incorrectly.
uncle_alicea at 2007-7-12 10:02:49 > top of Java-index,Java Essentials,Java Programming...
# 3
I'm sorry. That was a silly error. The compiler output made it seem as if T remained unbounded as apposed to just a mismatch between lhs and rhs. My apologies.
DejasPerPera at 2007-7-12 10:02:49 > top of Java-index,Java Essentials,Java Programming...
# 4

No need to apologize; that is a very misleading error message. I would encourage you to submit a bug report about it, but that has never worked very well for me. Whoever screens the bug reports always assumes you're still befuddled by the error message, not realizing that the message itself is what you're trying to fix.

uncle_alicea at 2007-7-12 10:02:49 > top of Java-index,Java Essentials,Java Programming...