首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >锡兰和Java之间的互操作性:如何共享来自'ceylon.language‘的导入

锡兰和Java之间的互操作性:如何共享来自'ceylon.language‘的导入
EN

Stack Overflow用户
提问于 2016-08-06 02:19:34
回答 1查看 122关注 0票数 0

我正在尝试将一个从ceylon.interop.java { CeylonList }派生的ceylon类放到包含这个派生的ceylon类的ceylon模块之外的一个java单元中(在ceylon术语中,这将被称为模块,但java还没有)。

run.ceylon:

代码语言:javascript
复制
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端可见,我在模块描述符中将导入的模块注释为“共享”。

module.ceylon:

代码语言:javascript
复制
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";
}

但是编译器仍然会报告错误:

代码语言:javascript
复制
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

代码语言:javascript
复制
...
    shared import ceylon.language "1.2.2";
...

但一方面,ceylon.language根本不允许导入,因此它既不能被注释,也不能重新导出。

另一方面,我找不到任何……未重新导出的已导入模块...‘因为所有导入的模块都被标注为共享的。

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

Use.java:

代码语言:javascript
复制
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‘的哪个超类型,并且来自未重新导出的导入模块,以及2.如何重新导出它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-06 02:44:11

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

在即将发布的Ceylon 1.2.3中,应该支持这一点,但我得到了与您相同的错误,并且没有看到示例代码有任何错误。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38795586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档