theMadKing
theMadKing

Reputation: 2074

Scala Reassigment to Val with Class (Setters/Getters)

I've made a custom class in Scala that looks like this:

class DQOpsStoreProfileStatusS extends Serializable{
  final val serialVersionUID = 1l
  private var _id:Int = _
  private var _runStatusId:Int = _
  private var _lakeHdfsPath:String = _

  def id = this._id
  def id_ = (_id:Int) = this._id = _id

  def runStatusId = this._runStatusId
  def runStatusId_ = (_runStatusId:Int) = this._runStatusId = _runStatusId

  def lakeHdfsPath = this._lakeHdfsPath
  def lakeHdfsPath_ = (_lakeHdfsPath:String) = this._lakeHdfsPath = _lakeHdfsPath
}

I reference this class in another object that looks like this:

 var colResult = new DQOpsStoreProfileStatusS
        colResult.fieldIndex = curIndex
        colResult.lakeHdfsPath = inputFileLocation

My two setters are complaining of "Reassignment to Val". I have looked through a bunch of examples and cant figure out what I am doing wrong?

Upvotes: 0

Views: 640

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170713

The method names for setters should end in _= without the space: def id_=(_id:Int) etc. You are instead defining methods without arguments called id_, runStatusId_ and lakeHdfsPath_.

Upvotes: 2

Related Questions