views:

498

answers:

4
[javac] C:\ws\galileo\test\Cacheable.java:13: incompatible types
[javac] found   : com.io.CacheType
[javac] required: com.io.CacheType
[javac]  public CacheType id() default CacheType.COMMON;

I really don't get this one. I have a project where I'm custom building a caching interceptor for Spring. It simply is a look by cache name to point to EhCache and uses aop-autoproxy to load the CacheableAspect (which is my caching intercepter). Now when I use the default value in the annotation, ANT gives me the compiler error below. I tried updating to the latest JDK (i'm on 1.6 16 now) and setting source/target levels in the ant script but no success. When I remove the default value and force all areas to specify a value, it compiles in ant fine.

It always worked in Eclipse, I had unit tests that ran perfectly with the previous default value.

What gives? I tried building a project (no spring) that simply echoed the configuration with ant and it compiled in ant fine (and in eclipse).

that tells me MAYBE it might be the spring auto-proxying somehow? but then why would the compiler not give me the generated type name? GRRRR. Any thoughts?

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.io.CacheType;

@Retention(RetentionPolicy.RUNTIME) 
@Target({ElementType.METHOD}) 
public @interface Cacheable {
 public CacheType value() default Cachetype.COMMON;
}

public enum CacheType {

 COMMON("common"),
 PERSISTENT("persistent";

 private String cache;

 CacheType(String cache) {
  this.cache = cache;
 }

 public String cache() {
  return this.cache;
 }
}
A: 

I wonder if it this is caused by defining Cacheable and CacheType in the same source file, and then importing "com.io.CacheType". That could conceivably make the compiler think that there are two classes called "com.io.CacheType".

Stephen C
A: 

Could you post the entire source file or something? The code you posted seems copy/pasted from different source files and is full of typos.

Normally the following should always do the trick when CacheType enum is in a different source file, you had a typo in CacheType.COMMON:

public @interface Cacheable {
 public CacheType value() default CacheType.COMMON;
}
NickDK
It was in a different source file and you're right looks like I have a typo. I'll post it when I get home since I'm at work right now.
+1  A: 

Have a look here: http://bugs.sun.com/view%5Fbug.do?bug%5Fid=6512707 this might be the cause of your problem.

magoo
The latest Sun JDK (6u20) still has this bug in. Compiling with either OpenJDK or JDT (part of eclipse) solved the problem for me. JDT can be used outside of eclipse (e.g. in ant) details here: http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm. To use pluggable annotation processors you will need org.eclipse.jdt.apt.pluggable.core<version>.jar and org.eclipse.jdt.compiler.apt<version>.jar in your classpath, these can be found in the plugins folder of the eclipse installation.
Reuben Peeris
A: 

Why do we have two public entities in a source file?

Calm Storm