3
什么可能是错误的?hector scala类型不匹配
val is = IntegerSerializer.get
mutator.addInsertion(deviceId, COLUMN_FAMILY_CARSTATUS, createColumn("mileage", 111, ss, is))}
ModelOperation.scala:96: error: type mismatch;
[INFO] found : me.prettyprint.cassandra.serializers.IntegerSerializer
[INFO] required: me.prettyprint.hector.api.Serializer[Any]
[INFO] Note: java.lang.Integer <: Any (and me.prettyprint.cassandra.serializers.IntegerSerializer <: me.prettyprint.cassandra.serializers.AbstractSerializer[java.lang.Integer]), but Java-defined trait Serializer is invariant in type T.
[INFO] You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
[INFO] mutator.addInsertion(deviceId, COLUMN_FAMILY_CARSTATUS, createColumn("mileage", 111, ss, is))}
不幸的是,你的解决方法不起作用。对于这段代码: 'val a = createColumn(“updateTime”,11,ss,IntegerSerializer.get.asInstanceOf [Serializer [_ <:Any]])' 我得到这个错误: 'error:type mismatch ; found:me.prettyprint.hector.api.Serializer [_ $ 2]其中type _ $ 2 必需:me.prettyprint.hector.api.Serializer [Any] 注意:_ $ 2 <:任何,但是由Java定义的trait Serializer在类型T中是不变的。 您可能希望研究通配符类型,例如\'_ <:Any \'。 (SLS 3.2.10) VAL A = createColumn( “注册”,11,SS,IntegerSerializer.get.asInstanceOf [串行[_ <:任何]])' – DarkAnthey
啊,对不起,我无法进行测试。如果只是投射到“Serializer [Any]”?我更新了答案。 –
顺便说一句,这里是相关的Java代码:https://github.com/rantav/hector/blob/master/core/src/main/java/me/prettyprint/cassandra/serializers/IntegerSerializer.java –