What is the difference between with and apply. From what I know the following code does the same thing:
swingElement.apply {
minWidth = ENABLED_COLUMN_WI
apply function//returns receiver T, T exposed as `this`
fun T.apply(block: T.() -> Unit): T
Description
The apply function is invoked on a receiver T, which will be exposed as this in the passed lambda expression. The receiver also becomes the result of apply automatically.
with function//return arbitrary value R, not an extension function, T exposed as `this`
fun with(receiver: T, block: T.() -> R): R
Description
The with function, as opposed to all other scope functions (let, run, also, apply), is not defined as an extension function. Instead, the function is invoked with a receiver object as its first argument explicitly. Same as apply, the receiver is exposed as this in the passed lambda. The result of the lambda, i.e. it’s last statement, becomes the result (R) of with.