open fun id(): Long
open fun id(id: Long): EpoxyModel<T>!
Override the default id in cases where the data subject naturally has an id, like an object from a database. This id can only be set before the model is added to the adapter, it is an error to change the id after that.
open fun id(@Nullable vararg ids: Number!): EpoxyModel<T>!
Use multiple numbers as the id for this model. Useful when you don't have a single long that represents a unique id.
This hashes the numbers, so there is a tiny risk of collision with other ids.
open fun id(id1: Long, id2: Long): EpoxyModel<T>!
Use two numbers as the id for this model. Useful when you don't have a single long that represents a unique id.
This hashes the two numbers, so there is a tiny risk of collision with other ids.
open fun id(@Nullable key: CharSequence?): EpoxyModel<T>!
Use a string as the model id. Useful for models that don't clearly map to a numerical id. This is preferable to using String#hashCode() because that is a 32 bit hash and this is a 64 bit hash, giving better spread and less chance of collision with other ids.
Since this uses a hashcode method to convert the String to a long there is a very small chance that you may have a collision with another id. Assuming an even spread of hashcodes, and several hundred models in the adapter, there would be roughly 1 in 100 trillion chance of a collision. (http://preshing.com/20110504/hash-collision-probabilities/)
See Also
IdUtils#hashString64Bit(CharSequence)
open fun id(@Nullable key: CharSequence?, @Nullable vararg otherKeys: CharSequence!): EpoxyModel<T>!
Use several strings to define the id of the model.
Similar to #id(CharSequence), but with additional strings.
open fun id(@Nullable key: CharSequence?, id: Long): EpoxyModel<T>!
Set an id that is namespaced with a string. This is useful when you need to show models of multiple types, side by side and don't want to risk id collisions.
Since this uses a hashcode method to convert the String to a long there is a very small chance that you may have a collision with another id. Assuming an even spread of hashcodes, and several hundred models in the adapter, there would be roughly 1 in 100 trillion chance of a collision. (http://preshing.com/20110504/hash-collision-probabilities/)
See Also
IdUtils#hashString64Bit(CharSequence)IdUtils#hashLong64Bit(long)