Mixing scala and java in Play Framework

后端 未结 4 1032
耶瑟儿~
耶瑟儿~ 2021-01-06 04:53

I have a Java file that looks like this:

package AuthorizeNetFingerprint;


class Fingerprint {
    private static Log logger = LogFactory.getLog(Fingerprint         


        
4条回答
  •  孤城傲影
    2021-01-06 05:05

    Three things:

    1. As you've already figured out, your Fingerprint class needs to be public.
    2. You've made Fingerprint's constructor private; you can't instantiate it.
    3. Any static methods in a Java class should be accessed through the class' companion object in Scala.

    All the Scala code in your example should be replaced by:

    val x_fp_hash = AuthorizeNetFingerprint.Fingerprint.createFingerprint(…)
    

    This works in the Scala (2.9.1) console, compiled with sbt (0.11.3).

    Yes, you can mix Java and Scala in a Play2 application, just put the Java code in the app directory. Note that Java classes need to be in their corresponding package directories, which is not the case for Scala classes.

提交回复
热议问题