Scala newbie running into a problem here:
val cache: LoadingCache[Long, String] = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build(
new CacheLoader [Long, String] {
override def load(key: Long): String = key.toString
})
And got build time error:
Error:(12, 11) type mismatch;
found : com.google.common.cache.LoadingCache[Long,String]
required: com.google.common.cache.LoadingCache[Long,String]
Note: Long <: Long, but Java-defined trait LoadingCache is invariant in type K.
You may wish to investigate a wildcard type such as _ <: Long
. (SLS 3.2.10)
.build(
What's the right fix here? Why the code is wrong? Thanks.