我正在尝试将一个从ceylon.interop.java { CeylonList }派生的ceylon类放到包含这个派生的ceylon类的ceylon模块之外的一个java单元中(在ceylon术语中,这将被称为模块,但java还没有)。
run.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端可见,我在模块描述符中将导入的模块注释为“共享”。
module.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根本不允许导入,因此它既不能被注释,也不能重新导出。
另一方面,我找不到任何……未重新导出的已导入模块...‘因为所有导入的模块都被标注为共享的。
旁白:然后在Use.java中导入并使用来自run.ceylon的类CL
Use.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‘的哪个超类型,并且来自未重新导出的导入模块,以及2.如何重新导出它?
发布于 2016-08-06 02:44:11
在Ceylon 1.2.2中,您的示例将不起作用,因为Java代码不能在同一模块中使用Ceylon声明。
在即将发布的Ceylon 1.2.3中,应该支持这一点,但我得到了与您相同的错误,并且没有看到示例代码有任何错误。
https://stackoverflow.com/questions/38795586
复制相似问题