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 –