Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Generics type inference resolved by javac and IDEA, but not in Eclipse(Java generics type inference)
Generics type inference resolved by javac and IDEA, but not in Eclipse [message #784441] Fri, 27 January 2012 14:35 Go to next message
Simone Tripodi is currently offline Simone TripodiFriend
Messages: 3
Registered: January 2012
Junior Member
HI all guys,

at Apache Commons we are developing a Sandbox component to work with Graph structures, approaching the problem with fluent APIs and Generics.

We have an issue with Generics in Eclipse that we need to fix in order to redistribute the library in a decent state to be used inside the most used IDEs: the CommonsGraph class contains the following method signature:

public static <V extends Vertex, WE extends WeightedEdge<W>, W, G extends Graph<V, WE>> SpanningTreeSourceSelector<V, W, WE, G> minimumSpanningTree( G graph )


When passing an argument that looks like:

UndirectedMutableWeightedGraph<BaseLabeledVertex, BaseLabeledWeightedEdge<Double>, Double> input = ...;
minimumSpanningTree( input )...


Eclipse detectes the following problem:

Bound mismatch: The generic method minimumSpanningTree(G) of type CommonsGraph<V,E,G> is not applicable for the arguments (UndirectedMutableWeightedGraph<BaseLabeledVertex,BaseLabeledWeightedEdge<Double>,Double>). The inferred type BaseLabeledWeightedEdge<Double> is not a valid substitute for the bounded parameter <WE extends WeightedEdge<W>>


Please note that the following code works when compiled from command line (via Apache Maven) and in IntelliJ IDEA, unfortunately I didn't figure out how to have it fixed in Eclipse as well.

Can someone give me an explanation about what happens and how to fix it, please? I'll be available to provide as much details as possible!

Many thanks in advance, all the best!!!
-Simo
Re: Generics type inference resolved by javac and IDEA, but not in Eclipse [message #786408 is a reply to message #784441] Mon, 30 January 2012 11:41 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
Oracle Java7 also reports an error for this while Oracle Java6 passes. Here is a simplified test case.
public class Snippet {
	public class WeightedEdge<T> {}
	public class Graph<T> {}
	public <W, WE extends WeightedEdge<W>, G extends Graph<WE>> void minimumSpanningTree( G graph ) {
		return;		
	}	
	public void foo() {
		Graph<WeightedEdge<Double>> input = null;
		minimumSpanningTree( input );
	}
}
Re: Generics type inference resolved by javac and IDEA, but not in Eclipse [message #786413 is a reply to message #786408] Mon, 30 January 2012 11:48 Go to previous messageGo to next message
Simone Tripodi is currently offline Simone TripodiFriend
Messages: 3
Registered: January 2012
Junior Member
Thanks for the kind feedback Satyam!

may I can kindly ask you if you have already an idea how to modify the APIs in a way to have this fixed?

Many thanks in advance, all the best!!!
Re: Generics type inference resolved by javac and IDEA, but not in Eclipse [message #787211 is a reply to message #786413] Tue, 31 January 2012 09:31 Go to previous messageGo to next message
Srikanth Sankaran is currently offline Srikanth SankaranFriend
Messages: 5
Registered: July 2009
Junior Member
Could you attach a full enough test case that shows the problem ?
As Satyam did, you should try to compile the code with JDK7 compiler
to see how it behaves and also with the latest Eclipse release to see
how eclipse behaves. Many times JDK7 compiler bug fixes are not
backported to JDK6 or JDK5.

Without knowing the relations between various types referred to in
your snippet, it is hard to tell. Even when the relationships are
known, we should only be able to explain what is wrong, but not necessarily
how to fix it.
Re: Generics type inference resolved by javac and IDEA, but not in Eclipse [message #793780 is a reply to message #786408] Wed, 08 February 2012 15:03 Go to previous message
Simone Tripodi is currently offline Simone TripodiFriend
Messages: 3
Registered: January 2012
Junior Member
Hi al

FYI we circumvented the problem with overloading, using a custom interface to represent WeightedGraphs. You can see the effort of our lovely community on Apache's JIRA, see SANDBOX-388 issue

Take care,
Simo

[Updated on: Wed, 08 February 2012 15:03]

Report message to a moderator

Previous Topic:Shortcut key to localize the class in the package explorer
Next Topic:HTTP Status 404: Eclipse Java EE IDE Tomcat
Goto Forum:
  


Current Time: Mon Sep 23 03:44:03 GMT 2024

Powered by FUDForum. Page generated in 0.03491 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top