标记为泛型,包含$ eq

时间:2018-08-17 14:33:40

标签: mongodb scala shapeless

Shapeless 2.3.3 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,而不是{{1}}。

此行为是无形的怪癖还是其他?还有其他标识符名称会导致异常行为吗?

我需要MongoDB序列化,这让我头疼……

1 个答案:

答案 0 :(得分:1)

根据Q中Alexey的评论,由于scala / java互操作的工作方式,这是Shapeless的“功能”。后者在Daniel Spiewak's blot post中的“运算符和超载”下进行了解释。

每个博客影响的操作员列表为:

op  Compiles To
=   $eq
>   $greater
<   $less
+   $plus
-   $minus
*   $times
/   div
!   $bang
@   $at
#   $hash
%   $percent
^   $up
&   $amp
~   $tilde
?   $qmark
|   $bar
\   $bslash
:   $colon