English 中文(简体)
Scala s 2.9.1汇编者是否丢弃了类型的参数信息?
原标题:Does Scala s 2.9.1 compiler throw away type parameter information?

我撰写了一些 Java法,这部法律取决于某些Schala法(我也写过)。 如果将Schala编成2.8.0,但如果我使用2.9.1,则无法提供一种参数类型的论点,似乎正在发挥作用。

(简化) 具体法则大致如此:

package test

import collection.JavaConversions._

class SomeClass {
  def foo(numbers: java.util.Set[Long]) {
    numbers.foreach(println(_))
  }
}

汇编了2.8和2.9.1汇编者。 Java法典就是这样:

package test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class App {

    public static void main(String[] args) {
        new SomeClass().foo(new HashSet<Long>(Arrays.asList(1L, 2L, 3L)));
    }

}

如果我把Schala编成2.8.0的汇编者,那么,Java将 compileppily(有1.6.0_26的汇编者)。 然而,如果我用2.9.1汇编Schala,那么 Java编者就错了:

testApp.java:16: foo(java.util.Set<java.lang.Object>) in test.SomeClass cannot be applied to (java.util.HashSet<java.lang.Long>)
            sc.foo(new HashSet<Long>(Arrays.asList(1L, 2L, 3L)));
              ^
1 error

因此,尽管Schala 2.8.0在星号中保留了以下信息: number is of categorySet<Long>,但2.9.1 汇编成特代码,其中/code>为Set<Object>

这难道是一种ug吗? 蓄意改变是否是不幸的(对我而言)副作用? (The Scala changelog 内提到“vach fixes in ......code>JavaConversions,用于更顺利地开展相互合作”。 如果是的话,我能做些什么来与2.9.1合作?

最佳回答

奥基被我打在黑暗的评论中,证明是 l,也是答案。

它的工作

def foo(numbers: java.util.Set[java.lang.Long])

<代码>java.lang.Long与Scala的<代码>Long不相同。 值得注意的是,Set[java.lang.Long]可包括null,Set[Long]不应(除非类型系统被绕过某种未加检查的投放)。 尽管有<代码>, 正在执行的《<<>条/条码》中载有这两种情况的提法;第二种情况是,保证其无效。

识别Set[Long]Set[java.lang.Long]在类型系统中打开了漏洞。 尽管如此,我不知道这一改动是否打算。

问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签