<@U0Z3FGCV8> this code ``` public class DataClass ...
# android
k
@audhil this code
Copy code
public class DataClass {

    private final String a;
    private final int b;

    public DataClass(final String a, final int b) {
        this.a = a;
        this.b = b;
    }

    public String getA() {
        return a;
    }

    public int getB() {
        return b;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        DataClass dataClass = (DataClass) o;

        if (b != dataClass.b)
            return false;
        return a != null ? a.equals(dataClass.a) : dataClass.a == null;
    }

    @Override
    public int hashCode() {
        int result = a != null ? a.hashCode() : 0;
        result = 31 * result + b;
        return result;
    }
}
is converted to
Copy code
class DataClass(val a: String?, val b: Int) {

    override fun equals(o: Any?): Boolean {
        if (this === o)
            return true
        if (o == null || javaClass != o.javaClass)
            return false

        val dataClass = o as DataClass?

        if (b != dataClass!!.b)
            return false
        return if (a != null) a == dataClass.a else dataClass.a == null
    }

    override fun hashCode(): Int {
        var result = a?.hashCode() ?: 0
        result = 31 * result + b
        return result
    }
}
you just have to add the
data
modifier and remove
equals
and
hashCode
yourself
👍 1
a
kirillrakhman: thank you so much, I think this'll work
@kirillrakhman
k
@audhil if you remove
equals
and
hashCode
beforehand, it's even easier
1
f
Intellij itself has the action “Covert to kotlin”, and do the exact task that you need
k
that's what I was talking about, but I guess I could have made that clearer