Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

incompatible types found: required: default enums in annotations

[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;
 }
}
like image 764
Core Avatar asked Sep 15 '09 04:09

Core


1 Answers

Still present in JDK 6u25, but adding package to default value does the trick:

CacheType value() default com.io.CacheType.COMMON;
like image 98
yurez Avatar answered Sep 21 '22 14:09

yurez