obj?.fn()
calls fn
member function if the object isn't null, otherwise doesn't do anything.
obj!.fn()
on the other hand asserts that obj
isn't null, and calls fn
. If the object is null, you get an exception.
So it's a difference in assertiveness: you either ask or simply claim the nullable property of a nullable object.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…