How do you call a Scala singleton method from Java?

前端 未结 5 1527
渐次进展
渐次进展 2020-12-05 23:52

I\'m trying to inject some Scala code into my existing Java app. (So, being said, I want some more fun).

I create a singleton stuff in Scala

ScalaPow         


        
5条回答
  •  無奈伤痛
    2020-12-06 00:29

    What were the errors you were getting? Using your Scala sample and the following Java class:

    cat test.java:

    
    import org.fun.*;
    
    public class test {
        public static void main(String args[]) {
           System.out.println("show my power: " + ScalaPower.showMyPower(3));       
        }
    }
    

    And running it as follows:

    java -cp .:<path-to/scala/install-dir>/lib/scala-library.jar test

    gives my the output:

    show my power: 0, 1, 2

提交回复
热议问题