你如何从Java调用Scala对象?
Java 代码:
import javax.swing.Timer;
class Main {
public static void main(String args[]) {
MyListener myListener = new MyListener();
Timer timer = new Timer(1000, myListener);
timer.start();
while(timer.isRunning()) {
System.out.print(".");
}
}
}
Scala code:
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class MyListener extends ActionListener {
override def actionPerformed(arg0: ActionEvent) {
println("Do something");
}
}
命令行:
scalac MyListener.scala
javac Main.java
java -cp /usr/share/java/scala-library.jar:. Main