加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

spring – kotlin中的数字不可序列化

发布时间:2020-12-15 01:43:34 所属栏目:大数据 来源:网络整理
导读:我发现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

我发现kotlin中的数字不可序列化.

>第一个问题

Device.kt:

package test.domain

import javax.persistence.*

Entity public class Device {
    public Id GeneratedValue var id: Long = -1
    public var name: String = ""
    ...
}

DeviceRestRepository.kt:

package test.domain

import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.data.repository.query.Param
import org.springframework.data.rest.core.annotation.RepositoryRestResource

RepositoryRestResource(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.domain

import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.data.repository.query.Param
import org.springframework.data.rest.core.annotation.RepositoryRestResource

RepositoryRestResource(collectionResourceRel = "device",java.lang.Long?> {
    public fun findByName(Param("name") name: String): List

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?’

最佳答案
至于Kotlin 1.0 Beta 1原始类型是可序列化的:

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/

因此,您不再有任何问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读