Created
February 24, 2012 15:32
-
-
Save sheki/1901650 to your computer and use it in GitHub Desktop.
What is the compile error here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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