本文介绍了为什么我需要jsr305在scala中使用番石榴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下scala文件:

I have the following scala file:

object SGuavaTryout {
  com.google.common.cache.CacheBuilder.newBuilder()
}

我在类路径中使用guava-11.0.2.jar进行编译.我的scala 2.9.1编译器(eclipse插件和纯scalac)都抱怨:

I compile with guava-11.0.2.jar in the classpath. My scala 2.9.1 compiler (both eclipse plugin and plain scalac) complains:

error while loading CacheBuilder, Missing dependency
  'class javax.annotation.CheckReturnValue', required by
  D:\devel\eclipse-workspace\Scala Spielwiese\guava-11.0.2.jar
  (com/google/common/cache/CacheBuilder.class)

要进行编译,我需要将jsr305(jsr305-1.3.9.jar)添加到构建路径.在没有jsr305的情况下,Java等效编译就可以了:

To compile, I need to add jsr305 (jsr305-1.3.9.jar) to the build path. The java equivalent compiles just fine without jsr305:

public class JGuavaTryout {
  public void tryout() {
    com.google.common.cache.CacheBuilder.newBuilder();
  }
}

任何想法为何scala需要jsr305?番石榴有官方的jsr305实现吗?

Any ideas why scala requires jsr305? Is there an official jsr305 implementation to use with guava?

谢谢! -乔治

推荐答案

这是因为Scala编译器的设计方式,它要求类公开的所有类型在编译时都可用,而Java编译器实际上没有不在乎.

That's because of the way the Scala compiler is designed, it requires all the types exposed by a class to be available at compile time, whereas the Java compiler effectively doesn't care.

这篇关于为什么我需要jsr305在scala中使用番石榴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:01