[英]CacheBuilder.newBuilder().build is ambiguous
I'm trying to use a snippet of code for a Stash plugin, but the compiler keeps giving me an error that I can't seem to solve. 我正在尝试为Stash插件使用一小段代码,但是编译器一直在给我一个似乎无法解决的错误。 It's using com.google.common.cache.Cache (Guava) 它使用的是com.google.common.cache.Cache(Guava)
static final RepositorySettings DEFAULT_SETTINGS = new RepositorySettings(0);
private final PluginSettings pluginSettings;
private final Cache<Integer, RepositorySettings> cache = CacheBuilder.newBuilder().build(
new CacheLoader<Integer, RepositorySettings>()
{
@Override
public RepositorySettings load(@Nonnull Integer repositoryId)
{
@SuppressWarnings("unchecked")
Map<String, String> data = (Map) pluginSettings.get(repositoryId.toString());
return data == null ? DEFAULT_SETTINGS : deserialize(data);
}
});
The .build is giving me the following error .build给我以下错误
The method build(CacheLoader<? super Integer,RepositorySettings>) is ambiguous for the type CacheBuilder<Object,Object>
Cache has a build()
method that takes no parameters, LoadingCache
on the other hand has a build()
method that takes CacheLoader
as a parameter. Cache具有不带参数的build()
方法,而LoadingCache
具有带CacheLoader
作为参数的build()
方法。
private final LoadingCache<Integer, RepositorySettings> cache = CacheBuilder.newBuilder().build(
new CacheLoader<Integer, RepositorySettings>() {
@Override
public RepositorySettings load(@Nonnull Integer repositoryId) {
@SuppressWarnings("unchecked")
Map<String, String> data = (Map) pluginSettings.get(repositoryId.toString());
return data == null ? DEFAULT_SETTINGS : deserialize(data);
}
});
This should work. 这应该工作。
As reference: http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilder.html 作为参考: http : //docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilder.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.