Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Remove toString() implementation from Kotlin data classes

License

Notifications You must be signed in to change notification settings

CherryPerry/DataClassNoString

Repository files navigation

DataClassNoString

Download License Build Status

Kotlin compiler plugin, that removes toString(), equals(any: Any) and hashCode() functions from your data classes.

Motivation

Kotlin is cool and data class are cool. But sometimes we overuse them in places where we actually do not need to. So the question is what is a price of using data classes when we actually do not need them? To answer this question I decide to explore edge case situation when we consider all data classes in a project as useless and replaceable with simple classes. After applying this compiler plugin we should see the price (APK size) which we pay for using data classes.

Usage

buildscript {
    repositories {
        maven { url 'https://dl.bintray.com/cherryperry/maven' }
    }
    dependencies {
        classpath 'com.cherryperry.nostrings:gradle-plugin:VERSION'
    }
}

repositories {
    maven { url 'https://dl.bintray.com/cherryperry/maven' }
}

apply plugin: 'com.cherryperry.nostrings'

dataClassNoString {
    enabled = true / false
    removeAll = true / false // Remove everything or toString() only
}

Compile your app and compare the results by using diffuse.

You should see the difference in dex size, method and string count.

About

Remove toString() implementation from Kotlin data classes

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages