标量分配值给对象 [英] scala assign value to object

查看:63
本文介绍了标量分配值给对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

 def getContentComponents: Action[AnyContent] = Action.async {
        contentComponentDTO.list().map(contentComponentsFuture =>
          contentComponentsFuture.foreach(contentComponentFuture =>

            contentComponentFuture.typeOf match {
              case 5 =>
                contentComponentDTO.getContentComponentText(contentComponentFuture.id.get).map(
                  text => contentComponentFuture.text = text.text
                )
            }
          )
            Ok(Json.toJson(contentComponentsFuture))
        )

并在分配值时得到此错误消息:

and get this error message while assigning a value:

有没有办法解决这个问题?

Is there a way to solve this issue?

我曾考虑过要创建一个副本,但这意味着我以后还会做很多其他事情.如果我可以重新分配值,对我来说会容易得多.

I thought about creating a copy but that would mean that I have do lots of other stuff later. It would be much easier for me if I could reassign the value.

谢谢

推荐答案

刚刚找到解决方案...

Just found the solution ...

在模型中,我必须将属性定义为var

In model I have to define the Attributes as var

case class ContentComponentModel(
                              id: Option[Int] = None,
                              typeOf: Int,
                              name: String,
                              version: String,
                              reusable: Option[Boolean],
                              createdat: Date,
                              updatedat: Date,
                              deleted: Boolean,
                              processStepId: Int,
                              var text: Option[String],

这篇关于标量分配值给对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆