https://kotlinlang.org logo
#getting-started
Title
# getting-started
s

Shawn

02/21/2024, 6:41 PM
but also, if you're only using one class here, why not just use
filterIsInstance<T>
?
🧵 3
🐛 1
r

Ray Rahke

02/21/2024, 7:23 PM
is this faster in terms of performance?
s

Shawn

02/21/2024, 7:24 PM
faster than what?
r

Ray Rahke

02/21/2024, 7:24 PM
just doing a filter { }
s

Shawn

02/21/2024, 7:26 PM
if you just
filter
, you'll have to cast afterwards
r

Ray Rahke

02/21/2024, 7:28 PM
Untitled.cpp
Cannot use 'T' as reified type parameter. Use a class instead.
s

Shawn

02/21/2024, 7:29 PM
Copy code
inline fun <reified T : AbstractBase> find(): T {
    return instances.filterIsInstance<T>().first()
}
r

Ray Rahke

02/21/2024, 7:30 PM
and i can use inline for methods on classes I assume
yes
s

Shawn

02/21/2024, 7:30 PM
yep
r

Ray Rahke

02/21/2024, 7:36 PM
@Shawn thanks a lot for your help
👍 1