0

I don't understand why an ArrayList of String cannot be stored in an ArrayList of CharSequence as String is a subtype of CharSequence in Java ?

ArrayList<CharSequence> str = new ArrayList<String>(); // does not compile

enter image description here

What's the issue with the inheritance that cause the compiler to fail ?

In Kotlin, the same line compiles :

val list: List<CharSequence> = ArrayList<String>(listOf(""))

Do you know why it fails in Java ?

0 Answers0