java - Ceylon 和 Java 之间的互操作性 : How to share an import from 'ceylon.language'

标签 java interop ceylon

我正在尝试将从 ceylon.interop.java { CeylonList } 派生的 ceylon 类设置为 ceylon 模块外部的 java 单元(用 ceylon 术语来说,这将被称为模块,但 java 还没有)包含这个派生的 Ceylon 类。

运行.ceylon:

import java.util {
    JList=List
}

import ceylon.interop.java {
    CeylonList
}

// CL is deliberately annotated as 'shared' - this is the crucial point !!
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {}

为了使导入的模块在 java 端可见,我在模块描述符中将导入的模块注释为“共享”。

模块.ceylon:

native ("jvm") module com.example.simple "1.0.0" {
    shared import "java.base" "8";
    shared import ceylon.collection "1.2.2";
    shared import ceylon.interop.java "1.2.2";
}

但是编译器仍然报错:

source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'Collection<Integer>' involves an unexported type declaration
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {}
                 ^
source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'List<Integer>' involves an unexported type declaration
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {}
                 ^
source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'Correspondence<Integer,Integer>' involves an unexported type declaration
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {}
                 ^
source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'Ranged<Integer,Integer,List<Integer>>' involves an unexported type declaration
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {}

解决方案应该是重新导出 ceylon.language

...
    shared import ceylon.language "1.2.2";
...

但一方面,ceylon.language 根本不允许导入,因此无法对其进行注释或重新导出。

另一方面,我无法发现任何“...未重新导出的导入模块...”,因为所有导入的模块都被注释为共享。

旁白:然后将 run.ceylon 中的类 CL 导入并在 Use.java 中使用

使用.java:

package some.other.package
// And thus some.other.module if there were

import com.example.simple.*;
import java.util.* ;

public class  Use{
  public static void main (String[] args) {

    LinkedList ll = new LinkedList();
    ll.add(1);
    ll.add(2);

    CL c = new CL(ll);

  }
}

现在的问题是(引用上面的错误信息), 1. 类型“CL”的哪种父类(super class)型在此模块外部可见并且来自未重新导出的导入模块,以及 2.如何重新导出?

最佳答案

在 Ceylon 1.2.2 中,您的示例将不起作用,因为 Java 代码无法使用同一模块中的 Ceylon 声明。

在尚未发布的 Ceylon 1.2.3 中,应该支持此功能,但我遇到了与您相同的错误,并且示例代码没有发现任何问题。

关于java - Ceylon 和 Java 之间的互操作性 : How to share an import from 'ceylon.language' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38795586/

相关文章:

java - 如何在jsoup中提取属性

java - ceylon 目录的 Jimfs 路径

java - 使用 spring 和 java 遍历文件中的所有属性

java - 如何将对象传递给 Controller ​​中的 ModelAttribute - Spring

c# - PInvoke 和 double*

c# - 将 "Treat wchar_t as built-in type"设置为 No 会影响 C# 互操作吗?

ceylon - ceylon 中是否有与 scala 的 monadic-for/yield 语法等效的语法?

Linux 上的 java.lang.UnsatisfiedLinkError

c# - 使用 C# 类库作为 COM+ 服务器应用程序