且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Play 框架中混合使用 scala 和 java

更新时间:2023-08-24 17:06:28

三件事:

  1. 您已经知道,您的指纹类需要公开.
  2. 您已将 Fingerprint 的构造函数设为私有;你不能实例化它.
  3. Java 类中的任何静态方法都应通过该类在 Scala 中的伴随对象进行访问.

示例中的所有 Scala 代码都应替换为:

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

val x_fp_hash = AuthorizeNetFingerprint.Fingerprint.createFingerprint(…)

这适用于使用 sbt (0.11.3) 编译的 Scala (2.9.1) 控制台.

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

是的,您可以在 Play2 应用程序中混合使用 Java 和 Scala,只需将 Java 代码放在 app 目录中即可.请注意,Java 类需要在其对应的包目录中,而 Scala 类则不然.

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.