Search code examples
javagenericsguavajava-6

Looking for java 1.6 workaround to apparent compiler issue


This compiles fine with Java 1.7 but not with 1.6. (This is using Guava 14.0.1).

Cache<TokenCacheKey, CachedToken>tokenCache = CacheBuilder.<TokenCacheKey, CachedToken>from(PARAM.tokenCacheConfig).build();

Can anyone suggest an alternative that can be compiled in 1.6?


Solution

  • CacheBuilder#from(CacheBuilderSpec) is not a generic method. It seems, pre-Java 7, you could not provide type arguments to non-generic methods.

    Just remove the type arguments

    Cache<TokenCacheKey, CachedToken> tokenCache = CacheBuilder.from(PARAM.tokenCacheConfig).build();