interface One fun foo(): E where E : Number, E : One, R : One = null!! interface Entity abstract class SecuredEntity(val entity: E) where E : Entity, E : SecurityCodeAware<*,*> interface SecurityCodeAware> where E : Entity, E : SecurityCodeAware fun > SecurityCodeAware.secured() : R where E : Entity, E : SecurityCodeAware = when(this) { is Order -> SecuredOrder(this) else -> null!! } class Order : Entity class SecuredOrder(order: Order) : SecuredEntity<Order>(order) fun main() { val securedOrder = Order().secured() }