我試圖從ceylon.interop.java(CeylonList)派生出一個錫蘭類到java單元(用錫蘭語來說,這將是稱爲模塊,但java還沒有),在包含這個衍生錫蘭類的錫蘭模塊之外。Ceylon和Java之間的互操作性:如何共享從'ceylon.language'的導入
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是不允許被導入的,所以它不能被註釋,也不會被重新導出。
另一方面,我無法發現任何'...未重新導出的導入模塊...',因爲所有導入的模塊都註釋爲共享。
除了:從run.ceylon類CL然後導入並在Use.java
使用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.如何重新導出它?
@ user3464741你會介意在https://github.com/ceylon/ceylon/issues上提供這方面的錯誤報告嗎? –
不好意思,我忘記提到我用錫蘭1.2.3每晚編譯(上週)編譯它。如果我在run.ceylon中放棄'共享'註釋,而不是'共享類CL',那麼只有'class CL'),那麼ceylon聲明可以被同一模塊中的Java代碼使用。但不在模塊之外。這需要在run.ceyon中將CL註釋爲「共享」。正是這導致了錯誤。 – Michael
當然,我明白。我相信你提到的錯誤是特定於當前的1.2.3版本。 –