mongodb - 包含“$eq”的标记泛型
问题描述
Shapeless 2.3.3LabelledGeneric
在以下案例类上运行时返回一个奇怪的结果:
scala> case class Foo(`$eq`: Int)
defined class Foo
scala> LabelledGeneric[Foo]
res0: shapeless.LabelledGeneric[Foo]{type Repr = Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("=")],Int] :: shapeless.HNil} = shapeless.LabelledGeneric$$anon$1@1ac7dbd3
请注意,返回的标签实际上是=
而不是$eq
.
这种行为是无形的怪癖还是其他什么?是否有其他标识符名称会导致奇怪的行为?
我需要这个来进行 MongoDB 序列化,这对我来说是一个非常头疼的问题......
解决方案
根据 Alexey 在 Q 中的评论,这是 Shapeless 中的一个“功能”,因为 scala/java 互操作的工作方式。后者在Daniel Spiewak 的“运算符和超载”下的印迹文章中进行了解释。
根据博客,受此影响的运营商列表是:
op Compiles To
= $eq
> $greater
< $less
+ $plus
- $minus
* $times
/ div
! $bang
@ $at
# $hash
% $percent
^ $up
& $amp
~ $tilde
? $qmark
| $bar
\ $bslash
: $colon
推荐阅读
- javascript - 如何让 js 代码输出在特定的 DIV 后台运行
- google-ads-api - 根据 API 调用向 Search Ads 添加附加电话信息
- c# - 操作方法:使用 Microsoft.Office.Interop 打开/保存文件时,停止在快速访问中将文件添加到“最近的文件”
- python - 有没有一种简单的方法可以将函数嵌套在一起,以便它们从单个 raw_input 作为一个运行?
- javascript - 我可以从选定的单元格值中显示多行吗?
- reactjs - 如何重用带有钩子的 React 库
- java - 结合两个 java servlet 的输出
- security - 如何通过升级到 4.3 来转移到现有项目中编码器的“算法:自动”?
- amazon-web-services - 从在 VPC 内运行的 Lambda 访问 DynamoDB VPC Endpoint
- html - 如何在不实际单击按钮的情况下以编程方式从代码中打开 NgbPopOver