If I have a method like: ```public fun findLine(i:...
# getting-started
e
If I have a method like:
Copy code
public fun findLine(i: Int, required: Boolean): LineContext?
Can I describe that when
required
is hardcoded to
true
the return type is not-null with contracts? E.g.
Copy code
val result = findLine(0, true)
// result is of type LineContext. Note the missing ?
🚫 1
y
Seems like you should use 2 methods instead:
Copy code
public fun findLineOrNull(i: Int): LineContext?
public fun findLine(i: Int): LineContext
1
r
Wouldn't it be simpler to just overload it anyway?
Copy code
public fun findLine(i: Int): LineContext = findLine(i, true) ?: throw IllegalStateException("result should never be null if required is true")
e
Hey thanks! This is a bit of a particular use case as it applies to ANTLR. I didn't want to duplicate methods, mostly to keep the compiled size down. You can see what I ended up doing here https://github.com/Strumenta/antlr-kotlin/pull/142