scalacase-class

use case class in other package in scala


// vh.scala
class VH(temp: String) extends Serializable {
  case class car(name: String, color: String, year: Int) // case class I want to use in other package
}

I made class named VH, which will use in main scala

// main.scala
import packname.VH
val cars = nameRDD.map({ name=> car(name, "red", 2010) }).... // works well

til here, It's work as I wanted BUT below code is not work or compiled.

cars.map({ car=> tf.go( car)}) // it's what I want to do

// other.scala - tf class
import packname.VH // not work
class TF ... {
 def go( car: car) // not work
 def go( car: VH.car) // not work
}

How can I use case class define in other package class? Any Idea of this? Thanks.


Solution

  • Your car is a nested class, and it doesn't seem like it needs to be. Just move it outside VH. If it actually needs to be nested, you'll need a VH instance to work with it, e.g.

    def go(vh: VH)(car: vh.car)