Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following code:

 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:

enter image description here

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.

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
166 views
Welcome To Ask or Share your Answers For Others

1 Answer

Unfortunately this is not possible as contentComponentFuture.text is an immutable property so you cannot change its value like that.

The only way to "change" the values of the job object is to actually create a totally new instance and discard the old one. This is standard practice when dealing with immutable objects.

Sorry for the bad news.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...