I don’t think that’s a legal comparison, doubt the...
# getting-started
s
I don’t think that’s a legal comparison, doubt there’s a
compareTo(Any?)
defined
👍 2
h
So how might I go about defining that myself? Is it just a big chain of
when
for every type?
k
I would not recommend doing this.
If you just want to eg. sort a list and have
null
in from use
sortWith{ }
.
h
well, here's what I'm attempting to do.. I believe it should be clear from the code
Copy code
interface Consumable<Q: Quantity<Q>> {
    var quantityLostOnConsumption: ComparableQuantity<Q>
    var consumableQuantity: ComparableQuantity<Q>

    @JvmDefault
    fun consume(): Boolean {
        consumableQuantity -= quantityLostOnConsumption
        return consumableQuantity > null
    }
}
do you have a better recommendation?
k
No it's not clear and that's why it's not defined, what is
x > null
supposed to mean?
h
not empty
in this context
eh, i have a different idea
thanks for the advice
k
That would be
x != null
, right?
h
No, because it could go below the threshold, that's fine
The effects of consumption only trigger if this function returns true
so you'd hit the consume button and nothing would happen because there's nothing to consume
internally it'd read a negative quantity, but I'll include some garbage collection
but you may be correct. i'll try to write it a little more intuitively