0

Is there a way like transient keyword in kotlin that will equals all other attribute except a boolen var

As I have numerous attributes,I thought there must be a keyword for it.

Product.kt

@Parcelize
data class Product(
    val id: Int,
    val titleLine1: String? = null,
    val titleLine2: String? = null,
    val titleLine3: String? = null,
    val name: String? = null,
    val description: String? = null,
    val brand: String? = null,
    val brandId: Int? = null,
    val imageUrlLarge: String? = null,
    val price: Double? = null,
    val originalPrice: Double? = null,
    val splashUrl: String? = null,
    val category: String? = null,
    var onDiscount: Boolean? = null,
    val unit: String? = null,
    val conversionUnit: String? = null,
    val amount: Double? = null,
    val unitPrice: Double? = null,
    val url: String? = null,
    val breadCrumb: String? = null,
    val currency: String? = null,
    val productRank: Int? = null,
    var starRating: Double? = null,
    var reviewCount: Int? = null,
    val isFavourite: Boolean = false,
    val isRecommended: Boolean = false,
    val isSuggested: Boolean = false,
    val isPointsSuggested: Boolean = false,
    val isFavoriteOffer: Boolean = false,
    val isMissingOffer: Boolean = false,
    val isReplenished: Boolean = false,
    var splashes: List<Splash>? = null,
    var forSaleOnline: Boolean = false,
    val dynamicName: String? = null,
    val dynamicUrl: String? = null,
    val isClubMatasOnlyPrice: Boolean = false
) : Parcelable

I want to ignore isFavourite from equals method

2
  • 1
    Nope. All constructor parameters are used in equals. You either have to remove the ignored properties from the constructor, or implement your own equals. Commented Oct 3, 2023 at 13:53
  • 1
    You can move the property from the constructor into the body of the class. Commented Oct 3, 2023 at 14:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.