I m using Google Guava from a scala code. And an issue occurs when I m trying to use Int as a key type like in the example:
CacheBuilder.newBuilder()
.maximumSize(2)
.expireAfterWrite(24, TimeUnit.HOURS)
.build(
new CacheLoader[Int, String] {
def load(path: Int): String = {
path + "hello"
}
}
)
It seems to be fine, but the inferred type of created object is LoadingCache[Int with AnyRef, String]:
val cache: LoadingCache[Int with AnyRef, String] = CacheBuilder.newBuilder()
.maximumSize(2)
.expireAfterWrite(24, TimeUnit.HOURS)
.build(
new CacheLoader[Int, String] {
def load(path: Int): String = {
path + "hello"
}
}
)
And the error occurs when I m trying to get an element like in this example:
cache.get(1)
Scala compiler error:
[ERROR] error: type mismatch;
[INFO] found : Int(1)
[INFO] required: Int
[INFO] cache.get(1)
[INFO] ^
Can someone point me out why such error appears and what I m doing wrong?
ENV:
- Google Guava 15.0
- Scala 2.11.5