For this code
class Foo {
var name: String? = null
}
kotlin compiler generates:
private String name;
public final String getName() { ... }
public final void setName(String name) { ... }
Even if property name
doesn't have custom getter or setter.
It's possible to remove redundant get and set methods using @JvmField
annotation. So this code
class Foo {
@JvmField
var name: String? = null
}
generates only one field without additional methods.
public String name;
But is there any way to make kotlin compiler not generate getters and setters for all properties in entire project? No matter if it has annotation or not. Maybe some experimental compiler flags?
I want it because I have android instrumentation tests written on kotlin. Test apk exceeds 65k method count limit. About 2k of methods is generated getters/setters. I cannot use proguard or multidex due to some bugs in android build system. So removing kotlin synthetic methods will help me a lot.
minifyEnabled true
withuseProguard false
in your build configuration? – Grayce