0

我试图让这两个类连接起来。PatientMonitorExceptions.scala

abstract class PatientMonitorExceptions extends Exception
case class InvalidHeartRate (str:String) extends PatientMonitorExceptions

这是我尝试使用以下行编译的 main.scala:

main.scala

   import gasguru.patient.PatientMonitor
   import gasguru.patient.Patient
   import gasguru.patient.exceptions.InvalidHeartRate
   object Main extends App  {

    val p = new Patient("snyder","brad");
    val v = p.vitalSigns
    val pm = new PatientMonitor(p);
    p.vitalSigns.heartRate = 160;
    println("The patient's heart rate is: " +  p.vitalSigns.heartRate     + " bpm");
    try { pm checkHeartRate v.heartRate
    }
    catch {
      case InvalidHeartRate(x) => println(x);
      case _ => println("Something else");
    }
  }

我正在运行:scala main.scala编译此错误:加载 InvalidHeartRate 时出错,缺少 ./gasguru/patient/exceptions/InvalidHeartRate.class 所需的依赖项 'class InvalidHeartRate'

这个错误信息是什么意思?

4

1 回答 1

1

main.scala引用时InvalidHeartRate,它指的是为您的案例类创建的伴随对象InvalidHeartRate,并调用其上的unapply方法进行匹配。该InvalidHeartRate对象取决于InvalidHeartRate类路径中的案例类。出现错误消息是因为即使可以找到伴随对象的.class文件 ( ),但案例类本身的文件丢失 ( )。我建议删除所有文件并重新编译。InvalidHeartRate$.class.classInvalidHeartRate.class.class

于 2013-09-03T00:52:39.053 回答