0

HelloWorld.ceylon

import java.util { HashMap } //Error:(1, 8) ceylon: package not found in imported modules: java.util (define a module and add module import to its module descriptor)

void run() {
    print("test");

}

模块属性

module CeylonHelloWorld "1.0" {
    import java.base "8";
}

我在 HelloWord.ceylon 文件中遇到异常

4

3 回答 3

1

当我尝试该代码时,我得到:

Incorrect syntax: mismatched token CeylonHelloWorld expecting initial-lowercase identifier

module.ceylon.

模块的名称应该是格式foo.bar.baz(以句点分隔的首字母小写标识符)。

于 2014-10-23T20:47:02.050 回答
0

就像 Gavin 提到的,您必须使用合法的模块名称,当我将代码更改为使用模块名称“java8test”时,编译时会得到以下输出:

$ ceylon compile java8test
warning: It looks like you are using class files from a Java newer than 1.7.
  Everything should work well, but if not, let us know at https://github.com/ceylon/ceylon-compiler/issues.
  In the near future, the Ceylon compiler will be upgraded to handle Java 1.8.
./source/java8test/run.ceylon:1: warning: import is never used: 'HashMap'
import java.util { HashMap }
              ^
2 warnings
Note: Created module java8test/1.0.0

这一切都符合预期。

于 2014-10-24T10:47:35.513 回答
0

模块.ceylon

module holaCeylon "1.0.0"{
    import java.base "7"; // versión 7  JDK
}

包.ceylon

shared package holaCeylon;

现在我们回到 run.ceylon 文件并导入 java.util.HashMap Java 库。

运行.ceylon

import  java.util  { HashMap }

shared void run(){
   print("Importando librerias de Java en Ceylon"); 
   value romanos = HashMap<String,Integer>();
    romanos.put("I", 1);
    romanos.put("V", 5);
    romanos.put("X", 10);
    romanos.put("L", 50);
    romanos.put("C", 100);
    romanos.put("D", 500);
    romanos.put("M", 1000);
    print(romanos.values());
    print(romanos.keySet());
}

输出: 萨利达

代码: http ://codemonkeyjunior.blogspot.mx/2015/03/ceylon-interoperabilidad-con-java.html

于 2017-04-18T14:02:26.390 回答