`words is CharSequence` returns `false`. Isn't it ...
# announcements
p
words is CharSequence
returns
false
. Isn't it wierd?
s
No, because
words
is a List of Strings, not a String
☝️ 1
p
words
is not
CharSequence
, but the method signature says the receiver is
CharSequence
which creates the confusion.
Copy code
val ls = "abc".split("")
println(ls is CharSequence)
prints
false
Copy code
fun main() {
    val c = CLASS()
    println(c is INTERFACE)
}

interface INTERFACE

class CLASS : INTERFACE
prints
true
k
image.png
image.png
s
not weird in the slightest.
p
The example doesn't match the method signature.
k
which example?
p
The one in the picture I sent
a
you never captured the string into a variable to test its type against, you only captured
words
, which is the result of an operation performed on the string
p
But
words
is the variable on which
chunked
method is called, which is supposed to be of type
CharSequence
. I am really confused.
a
you're getting
Iterable<E>.chunked
, as posted in the pic above
p
That's what I mean. The example doesn't use the
chunked
function on
CharSequence
receiver but
Iterable
a
where's the confusion then?
words
is not a
CharSequence
, so it returns false for the
is
check
words
has the type of `.split(' ')`'s return type
which is not
CharSequence
p
I know,
fun CharSequence.chunked(size: Int): List<String>
is not the signature of the
chunked
call in the example but
fun Iterable<T>.chunked(size: Int): List<List<T>>
is
a
oh you're literally referring to the doc sample being for a different overload 🙂
p
so you got me?
a
looks like it's just a bad docs sample meant for the other overload
it's illustrating the correct behavior of a different function 🙂
p
yes, absolutely
a
probably worth filing a bug
p
k
Oh is this a sample in the docs?
p
yes
l
Yes, the shortcut is kotl.in/issue FYI @pavi2410