MG
Generic<T>
implicitly means Generic<T: Any?>
, which is not a subtype of Generic<Any>
.Type mismatch: inferred type is Vector<Byte> but Vector<Any?> was expected
Size: a a a
MG
Generic<T>
implicitly means Generic<T: Any?>
, which is not a subtype of Generic<Any>
.Type mismatch: inferred type is Vector<Byte> but Vector<Any?> was expected
MG
Any?
is MEANT to accept any possible type right?D
Any?
is MEANT to accept any possible type right?Vector<>
?MG
Vector<>
?А
D
AL
Type mismatch: inferred type is Vector<Byte> but Vector<Any?> was expected
open class VectorCore<out Type> {}Important thing is
open class VectorBase<out Type>: VectorCore<Type>() {
fun elementWiseOperation(vector: VectorCore<Any?>, action: (result: VectorCore<Any?>, lhs: Any?, rhs: Any?) -> Unit): VectorCore<Any?> = TODO()
fun t() {
val A = elementWiseOperation(this) { _, _, _ -> }
}
}
<out Type>
in the class declarationMG
Any?
SHOULD solve this right?open class Vector<Type> : VectorBase<Type> {
operator fun plus(vector: Vector<Any?>): Vector<Any> = elementWiseOperation(vector as Vector<Any>) { result, lhs, rhs ->
result.addDimension(addition(lhs, rhs))
} as Vector<Any>
}
val v1 = Vector<Byte>(3)
v1[0] = 1
v1[1] = 2
v1[2] = 3
val v2 = Vector<Byte>(3)
v2[0] = 1
v2[1] = 2
v2[2] = 3
println(v1)
println(v2)
println("v1 + v2 = ${v1 + v2}")
AL
Any?
SHOULD solve this right?open class Vector<Type> : VectorBase<Type> {
operator fun plus(vector: Vector<Any?>): Vector<Any> = elementWiseOperation(vector as Vector<Any>) { result, lhs, rhs ->
result.addDimension(addition(lhs, rhs))
} as Vector<Any>
}
val v1 = Vector<Byte>(3)
v1[0] = 1
v1[1] = 2
v1[2] = 3
val v2 = Vector<Byte>(3)
v2[0] = 1
v2[1] = 2
v2[2] = 3
println(v1)
println(v2)
println("v1 + v2 = ${v1 + v2}")
as Vector<Any>
) in Kotlin just because you have problems with types, it is pretty unsafe :)AM
А
MG
as Vector<Any>
) in Kotlin just because you have problems with types, it is pretty unsafe :)Number
type instead and just cast to the correct types via when ... is ...
expressionsfun a(v: Number) {}
a(5)
a(5.5)
a(5F)
АО
АО
fun a(v: Number) {
when (v) {
is Double -> …
…
}
}
MG
VM
private val authorizationAvailable: Boolean
get() = currentViewModel?.viewMode != ViewMode.UNAVAILABLE
VM
AL
AL
VM
viewMode