class A(val value : T) class B fun A.toB(): B { @Suppress("UNCHECKED_CAST") val v = (value as? Long)?.let { it.toInt() } as T ?: value return v }