You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by milan chudik <mi...@delfidata.no> on 2010/02/24 11:13:32 UTC
Generics 5 - unexpected type, found: java.lang.Object expected: reference
Hi guys,
I have a strange problem with one generics code found in one GWT
library. This compile fine with java 6 but not with java 5.
In fact I can compile it in eclipse with java 5, so this problem appears
only when compiling with maven.
I reproduced this error with this code:
class:
-----------------------------------
public class DogBean {
transient protected Object bean;
public <X> X getBean()
{
return (X) bean;
}
public void setBean(Object bean)
{
this.bean = bean;
}
}
--------------------------------
Call to this class (simplified):
----------------------------------
DogBean stack = new DogBean();
stack.setBean("My doggie");
if(stack.getBean() instanceof String)
{
System.out.println("GermanShepherd");
}
--------------------------------
I get this error on: if(stack.getBean() instanceof String)
-------------------------------------
[INFO] Compilation failure
/home/milan/projects/eclipse/workspace2/Generics/src/main/java/main/SomeClass.java:[24,32]
unexpected type
found : java.lang.Object
required: reference
------------------------------
This is my pom.xml - only one plugin.
pom.xml:
-----------------------------------------------
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
...
--------------------------------
Maven version:
--------------------------------
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
-----------------------
maven command used
--------------------------------
mvn clean install
--------------------------------
When I build it with jdk6 I can compile it without problem. But when I
use jdk5 when building, I get that error.
Problem is our build server use runs on jdk5, as some of our customers
do use jre 5.
I can cast this code like this:
if((Object)stack.getBean() instanceof String)
Then it compiles OK both with jdk5 and jdk6. but this is both ugly and dirty
But where is the problem?
I don't get this error under eclipse(neither under jd5 or jdk6) only
when building with maven
Any clues? Just ask for more info.
Regards,
Milan Chudík
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Generics 5 - unexpected type, found: java.lang.Object expected: reference
Posted by Jörg Schaible <jo...@gmx.de>.
milan chudik wrote at Mittwoch, 24. Februar 2010 11:13:
> Hi guys,
>
> I have a strange problem with one generics code found in one GWT
> library. This compile fine with java 6 but not with java 5.
> In fact I can compile it in eclipse with java 5, so this problem appears
> only when compiling with maven.
[snip]
No, it appears when you compile with the Sun compiler. Eclipse uses *never*
the compiler of the configured JDK. Simply compile from commandline with
javac yourself and you'll see. The Eclipse compiler is too smart regarding
generics.
- Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Generics 5 - unexpected type, found: java.lang.Object expected:
reference
Posted by milan chudik <mi...@delfidata.no>.
Thanks guys,
I wasn't aware of eclipse and its' compile routines.
milan
On 24/02/10 19:11, Wayne Fay wrote:
>> In fact I can compile it in eclipse with java 5, so this problem appears
>> only when compiling with maven.
>>
> ...
>
>> I don't get this error under eclipse(neither under jd5 or jdk6) only
>> when building with maven
>>
> Maven uses the compiler in your JDK while Eclipse uses its own
> compiler. This is not a Maven issue but rather a difference between
> the Eclipse compiler and Sun's compiler.
>
>
>> if((Object)stack.getBean() instanceof String)
>>
>> Then it compiles OK both with jdk5 and jdk6. but this is both ugly and dirty
>>
> I'd do this if it works.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
--
Med vennlig hilsen/Regards,
Milan Chudík
Fjøsangerveien 50
5892 Bergen
Norway
Mob. : +47 90094542
Tel. : +47 55209617
e-mail : milan.chudik@delfidata.no
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Generics 5 - unexpected type, found: java.lang.Object expected:
reference
Posted by Wayne Fay <wa...@gmail.com>.
> In fact I can compile it in eclipse with java 5, so this problem appears
> only when compiling with maven.
...
> I don't get this error under eclipse(neither under jd5 or jdk6) only
> when building with maven
Maven uses the compiler in your JDK while Eclipse uses its own
compiler. This is not a Maven issue but rather a difference between
the Eclipse compiler and Sun's compiler.
> if((Object)stack.getBean() instanceof String)
>
> Then it compiles OK both with jdk5 and jdk6. but this is both ugly and dirty
I'd do this if it works.
Wayne
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org