https://kotlinlang.org logo
#announcements
Title
# announcements
m

maplonki

06/06/2017, 4:55 AM
I’m trying to compare if 2 classes are of the same instance type but i’m getting an error because
this.contentFragment
is nullable, but i can just null check it
Copy code
var contentFragment: Fragment? = null

fun exec(contentFragment: Fragment) {
  if (contentFragment::class == this.contentFragment?::class) return
}
😱 3
k

kingsley

06/06/2017, 6:09 AM
maplonki: what do you mean by 2 classes of the same instance? Do you mean 2 instances of the same class? You could replace
::class
with
.javaClass
l

louiscad

06/06/2017, 6:47 AM
Not sure naming a parameter and a member property the same is a good practice 🤔
👍 2
m

myanmarking

06/06/2017, 8:56 AM
comparing instances is not done that way. you are only comparing if the class is the same
m

maplonki

06/06/2017, 6:22 PM
@kingsley yeah i meant, 2 instances of the same class, my bad, thanks for pointing that out 🙂
4 Views