Let's inspect the following code:
interface ValueHolder<out V> { val value: V}class IntHolder(override val value: Int) : ValueHolder<Int> class DoubleHolder(override val value: Double) : ValueHolder<Double>
The ValueHolder interface uses a generic to be able to hold a value of any type. The bytecode for the ValueHolder interface looks like this:
public abstract interface ValueHolder { public abstract getValue()Ljava/lang/Object; LOCALVARIABLE this LValueHolder; L0 L1 0}
The getValue() method returns an Object type because the compiler erases all generic types and replaces them with the first bound type. The first bound type is a type from which our generic extends. In the preceding example, the first bound type is ...