shapeless.~?>.witness[Nothing, Nothing, T](shapeless.~?>.rel[Nothing,Nothing])当scala版本从2升级到3

问题描述

我正在将我的 Scala 项目从版本 2 升级到 3。

这是我用于 Scala 版本 2 的 build.sbt

paintComponents(Graphics g)

以下是Scala代码示例-

repaint()

这适用于 Scala 版本 2。

现在我将 scala 版本升级到 3。

下面是build.sbt -

    scalaVersion := "2.13.5"
    version := "1.0.0"
    libraryDependencies += "com.chuusai" %% "shapeless" % "2.3.7"
    libraryDependencies += "org.scodec" %% "scodec-core" % "1.11.4"
    libraryDependencies += "org.slf4j" % "slf4j-log4j12" % "1.7.31"

以下是Scala版本3的代码-

    import scodec._
    import scodec.codecs._
    import scodec.bits._
    import scodec.codecs.implicits._
    import org.slf4j.LoggerFactory


    object AkkaEventSerializer {

      def toBinary(o: AnyRef): Array[Byte] =  o match {
        case e: Event => Codec.encode(e).require.toByteArray
        case x => throw new Exception(s"unexpected  object $x received which is ${x.getClass} type")
      }

      def fromBinary(bytes: Array[Byte],manifest: String): AnyRef = manifest match {
        case EventManifest => Codec[Event].decode(BitVector.apply(bytes)).require.value
        case x => throw new Exception(s"unexpected manifest $x in AdServerAkkaEventSerializer.fromBinary ")
      }

      final val EventManifest = classOf[Event].getName

      val  logger = LoggerFactory.getLogger(AkkaEventSerializer.getClass)

      case class Event(etype: Int,cp: Option[Double],userId: Option[String],buyerId: Option[String] = None)

    }

当我编译这个程序时,出现以下错误 -

[error] -- 错误:/Users/rajkumar.natarajan/Documents/Coding/OS/scala3-maven-build-demo/src/main/scala/com/serialize/AkkaEventSerializer.scala:17:36 [错误] 17 |案例 e:事件 => Codec.encode(e).require.toByteArray [错误] | ^ [错误] |找不到类型为 scodec.Codec[com.serialize.AkkaEventSerializer.Event] 的惰性隐式值。 [错误] |我发现: [错误] | [错误] | shapeless.~?>.witness[nothing,nothing,T](shapeless.~?>.rel[nothing,nothing]) [错误] |

[error] |但特征 NatTRel0 中的方法见证与类型 shapeless.Lazy[codec.Codec[com.serialize.AkkaEventSerializer.Event]] 不匹配。 [错误] -- 错误:/Users/rajkumar.natarajan/Documents/Coding/OS/scala3-maven-build-demo/src/main/scala/com/serialize/AkkaEventSerializer.scala:22:38 [错误] 22 | case EventManifest => Codec[Event].decode(BitVector.apply(bytes)).require.value [错误] | ^ [错误] |找不到类型为 scodec.Codec[com.serialize.AkkaEventSerializer.Event] 的惰性隐式值。 [错误] |我发现:

[错误] |

[错误] | shapeless.~?>.witness[nothing,nothing]) [错误] |

[error] |但特征 NatTRel0 中的方法见证与类型不匹配 shapeless.Lazy[codec.Codec[com.serialize.AkkaEventSerializer.Event]]。 [错误] 发现两个错误 [错误] 发现两个错误 [error] (Compile / compileIncremental) 编译失败

我知道我们可以使用 Scala 3 版本编译 Scala 2.13 代码。但我不能为这个代码

我该如何解决这个错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)