我发现kotlin中的数字不可序列化.
>第一个问题
Device.kt:
package test.domainimport javax.persistence.*Entity public class Device { public ID GeneratedValue var ID: Long = -1 public var name: String = "" ...}
DeviceRestRepository.kt:
package test.domainimport org.springframework.data.repository.PagingAndSortingRepositoryimport org.springframework.data.repository.query.Paramimport org.springframework.data.rest.core.annotation.RepositoryRestResourceRepositoryRestResource(collectionResourceRel = "device",path = "device")public trait DeviceRestRepository : PagingAndSortingRepository
我尝试编译此代码时出错,因为kotlin.Long不是Serializable:
Error:(14,72) Kotlin: Type argument is not within its bounds: should
be subtype of ‘java.io.Serializable?’
>第二个问题
我尝试使用java.lang.Long时遇到同样的错误:
DeviceRestRepository.kt:
package test.domainimport org.springframework.data.repository.PagingAndSortingRepositoryimport org.springframework.data.repository.query.Paramimport org.springframework.data.rest.core.annotation.RepositoryRestResourceRepositoryRestResource(collectionResourceRel = "device",java.lang.Long?> { public fun findByname(Param("name") name: String): List
最佳答案至于Kotlin 1.0 Beta 1原始类型是可序列化的:Warning:(14,72) Kotlin: This class shouldn’t be used in Kotlin. Use
kotlin.Long instead.Error:(14,72) Kotlin: Type argument is not
within its bounds: should be subtype of ‘java.io.Serializable?’
Int is Serializable
Now the type Int and other basic types are Serializable on the JVM. This should help many frameworks.
从:
http://blog.jetbrains.com/kotlin/2015/10/kotlin-1-0-beta-candidate-is-out/
因此,您不再有任何问题.
总结以上是内存溢出为你收集整理的spring – kotlin中的数字不可序列化全部内容,希望文章能够帮你解决spring – kotlin中的数字不可序列化所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)