Curro
Curro

Reputation: 1411

Wrong maven compilation error (works in eclipse)

I'm getting a compilation error when I compile using maven but works in eclipse. Both are using the same JDK:

java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)

mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/jdk1.6.0_35/jre
Default locale: es_ES, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-29-generic", arch: "amd64", family: "unix"

This is the error:

[ERROR] /blablabla.../myClass.java:    [78,107] inconvertible types
[ERROR] found   : java.util.Collection<java.lang.Object>
[ERROR] required: java.util.Collection<? extends org.springframework.integration.store.MessageGroup>
[ERROR] -> [Help 1]

And this is the code (no compilation error in eclipse):

Collection<? extends MessageGroup> collection = (Collection<? extends MessageGroup>) this.groupMap.values();

I know that this is a pretty recursive issue, I've found a few posts asking the same, but seems that nobody has a standar fix. Some people say that works with different JDK version. I have tested with 1.6.0_30, 1.6.0_31, 1.6.0_32 and 1.6.0_35 and all fail.

Any idea?

Thanks

Upvotes: 5

Views: 2295

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533442

I suspect eclipse isn't using the JDK you think it is. Try using type erasure.

Collection<? extends MessageGroup> collection = 
        (Collection<? extends MessageGroup>)
                (Collection) this.groupMap.values();

Upvotes: 14

Related Questions