非常简单的Scala 2.11.7功能我不知道,为什么有类型
推理错误:
a type was inferred to be `AnyVal`; this may indicate a programming error.
def isWrapper(is: FileInputStream): InputStream = {
^
虽然PushbackInputStream
- > FilterInputStream
- > InputStream
和GZIPInputStream
- > InflaterInputStream
- > FilterInputStream
- > InputStream
。
def isWrapper(is: FileInputStream): InputStream = {
val pb = new PushbackInputStream(is, 2)
val signature = new Array[Byte](2)
pb.read(signature)
pb.unread(signature)
if (signature.sameElements(Array(0x1F, 0x8B))) {
new GZIPInputStream(new BufferedInputStream(pb))
} else {
pb
}
}
错误表示评估if
块的结果不能是InputStream
。我为什么出错?如何解决这个问题?
答案 0 :(得分:3)
就是这个LUB:
scala> (new Array[Byte](2)).sameElements(Array(0x1F, 0x8B))
<console>:12: warning: a type was inferred to be `AnyVal`; this may indicate a programming error.
(new Array[Byte](2)).sameElements(Array(0x1F, 0x8B))
^
res1: Boolean = false
查看文档中的“完整”签名,以查看有害的B >: A
界限。
不确定为什么插入符号是关闭的。