objectboxobjectbox-android

Can an ObjectBox property have multiple annotations?


ObjectBox documents several annotations that can be applied to and entity's properties. Can one property have multiple annotations?

For example, would this be a valid entity?

@Entity
data class User(
    @Id 
    var id: Long = 0,
    @Index 
    @Unique(onConflict = ConflictStrategy.REPLACE)
    var name: String = null,
)

Solution

  • Yes, a property (and and entity) can have multiple annotations.

    Your example with @Index and @Unique is valid; however, because @Unique implies @Index, the latter is redundant and can be removed.