简体   繁体   English

val值bean如何变化

[英]How a val value bean changed

I use scala with mybatis: 我使用scala和mybatis:

Space.scala: Space.scala:

case class Space(
              val id: Long ,
              spaceName:String)

SpaceDao: SpaceDao:

   val space=Space(0,"space name")
   val mapper = session.getMapper(classOf[SpaceMapper])
   val result = mapper.insertSpace(space)
   println(space.id)

The result space id is the auto increment number of mysql, not 0. but both space and space.id is val, why a val value can be changed? 结果空间id是mysql的自动递增数,而不是0.但是space和space.id都是val,为什么val值可以改变?

This can be achieved via reflection (which is used by SetFieldInvoker ): 这可以通过反射 (由SetFieldInvoker使用 )来实现:

Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the Java virtual machine. 反射通常由程序使用,这些程序需要能够检查或修改在Java虚拟机中运行的应用程序的运行时行为。 This is a relatively advanced feature and should be used only by developers who have a strong grasp of the fundamentals of the language. 这是一个相对高级的功能,只有那些掌握了语言基础知识的开发人员才能使用。 With that caveat in mind, reflection is a powerful technique and can enable applications to perform operations which would otherwise be impossible. 考虑到这一点,反射是一种强大的技术,可以使应用程序执行本来不可能的操作。

Also see this question . 另见这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM