[kotlin] 추상 클래스에서 추상 메서드의 반환 형식을 다르게 지정하는 방법
abstract class Converter<T> {
    abstract fun convert(input: T): T
}

위의 예제에서 Converter 추상 클래스는 제네릭 타입 T를 사용하여 추상 메서드 convert의 반환 형식을 지정합니다. 이렇게 하면 하위 클래스에서 Converter를 상속받아 convert 메서드를 구현할 때 다양한 반환 형식을 지정할 수 있습니다.

예를 들어, Converter의 하위 클래스를 정의하여 다양한 반환 형식을 갖는 메서드를 구현할 수 있습니다.

class StringToIntConverter : Converter<String>() {
    override fun convert(input: String): Int {
        return input.toInt()
    }
}

class IntToStringConverter : Converter<Int>() {
    override fun convert(input: Int): String {
        return input.toString()
    }
}

위의 예제에서 StringToIntConverterIntToStringConverter는 각각 convert 메서드의 반환 형식을 다르게 지정하여 구현합니다. 이를 통해 추상 클래스에서 추상 메서드의 반환 형식을 다르게 지정할 수 있습니다.

위 예제는 Kotlin을 기반으로 하지만, 이와 유사한 원리는 다른 언어에서도 적용될 수 있습니다.