加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

.NET / CLR上Scala中的Reified泛型

发布时间:2020-12-16 09:57:24 所属栏目:安全 来源:网络整理
导读:Scala(至少在 JVM上)使用 type erasure进行Java兼容性.该 feature是 widely held to suck. Fixing this would be difficult on the JVM. In contrast to the JVM situation,.NET supports reified generics. Scala’s .NET implementation使用它们吗?如果没
Scala(至少在 JVM上)使用 type erasure进行Java兼容性.该 feature是 widely held to suck. Fixing this would be difficult on the JVM.

In contrast to the JVM situation,.NET supports reified generics. Scala’s .NET implementation使用它们吗?如果没有,可能,或者使用具体原因会出现什么问题?

解决方法

它正在进行中,小心翼翼地不要破坏JVM和.NET之间的Scala语义.

我在2011年就scala-tools邮件列表问了这个问题,Miguel Garcia给出了答案,他在其中概述了大局:

一些引言:

(1) What the Scala.Net preview currently does. As you have noticed,
the erasure phase also runs as part of the pipeline. This is a
“feature” of the preview version,a “feature” that had to be included
because support for CLR Generics wasn’t there yet (more on this
below). There is however one big advantage to running JVM-style
erasure in Scala.Net: all the Scala programs out there that rely on
the Scala library can already be compiled on .Net,instead of waiting
for CLR Generics to be ready. Those programs that rely on the Java JDK
can also be compiled,subject to IKVM support of the JDK APIs in
question [1].

(2) Support for CLR Generics in Scala.Net. The main motivation to
support it is gaining interoperability with existing assemblies. In
gaining that interoperability,care will be taken not to break away
from Scala semantics. In other words,any valid Scala program is going
to run and produce the same results on JVM and .NET. Which brings us
to the work in progress [2]. The initial prototype handles only the C#
subset of Scala. So now I’m addressing the rest. It’s more work than
initially anticipated but it’s important to cover the whole language.

A few more comments regarding interop with .NET assemblies,in
particular native issues. Yes,CLR assemblies can express using
“native int” (different sizes on different CPUs),P/Invoke of
C-functions exported by a .dll and such. Scala.Net does not aim to do
that low-level trickery. The assembly interoperability of interest is
at the level of “Common Language Specification”,i.e. what one
normally obtains from any C#,VB.NET,etc. compiler (“normally” i.e.
unless using “[DllImport]” attributes and related C++-isms).

Quoting from the CLI spec:

— start quote — The Common Language Specification (CLS) — The CLS is an agreement between language designers and framework (that is,
class library) designers. It specifies a subset of the CTS (Common
Type System) and a set of usage conventions.
Languages provide their users the greatest ability to access
frameworks by implementing at least those parts of the CTS that are
part of the CLS. Similarly,frameworks will be most widely used if
their publicly exported aspects (e.g.,classes,interfaces,methods,
and fields) use only types that are part of the CLS and that adhere to
the CLS conventions.
— end quote —

看看整个主题:

https://groups.google.com/forum/?fromgroups#!topic/scala-tools/JDjstK1_uvM

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读