Skip to content

Instantly share code, notes, and snippets.

@sheki
Created February 24, 2012 15:32
Show Gist options
  • Select an option

  • Save sheki/1901650 to your computer and use it in GitHub Desktop.

Select an option

Save sheki/1901650 to your computer and use it in GitHub Desktop.
What is the compile error here?
overloaded method value build with alternatives:
[error] [K1 <: java.lang.Object, V1 <: java.lang.Object]()com.google.common.cache.Cache[K1,V1] <and>
[error] [K1 <: java.lang.Object, V1 <: java.lang.Object](x$1: com.google.common.cache.CacheLoader[_ >: K1, V1])com.google.common.cache.LoadingCache[K1,V1]
[error] cannot be applied to (com.google.common.cache.CacheLoader[String,Long])
[error] .build(
[error] ^
[error] one error found
import java.util.concurrent.TimeUnit
import com.google.common.cache.{LoadingCache, CacheLoader, CacheBuilder}
/**
* using google guave instead of building our own like in the previous case.
*/
class QueueMetaCache extends ConfigSupport {
private val queueRefreshCache :LoadingCache[String, Long]= CacheBuilder.newBuilder()
.maximumSize(10000)
.expireAfterWrite(config.findInteger("refresh.cache.expiry.minute", 5), TimeUnit.MINUTES)
.build(
new CacheLoader[String, Long] {
def load(key: String) = QueueMetaStore.getResurfaceTime(key)
}
)
def refreshTime(queueName: String) = {
queueRefreshCache.get(queueName)
}
}
@bajohns

bajohns commented Dec 24, 2013

Copy link
Copy Markdown

The issue stems from the use of Long. If you use java.lang.Long the code will work. A more detailed explanation can be found there: http://stackoverflow.com/questions/16196290/scala-2-10-type-mismatch-using-google-guavas-cachebuilder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment