Skip to content

Instantly share code, notes, and snippets.

@kewp
Created September 6, 2018 13:03
Show Gist options
  • Save kewp/1efc1a4c406577342c43ccb258bf8739 to your computer and use it in GitHub Desktop.
Save kewp/1efc1a4c406577342c43ccb258bf8739 to your computer and use it in GitHub Desktop.
Kotlin Data Class - Java Equivalent
// Kotlin: data class Movie( val id: Int, val name: String )
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
public final class Movie {
private final int id;
@NotNull
private final String name;
public final int getId() {
return this.id;
}
@NotNull
public final String getName() {
return this.name;
}
public Movie(int id, @NotNull String name) {
Intrinsics.checkParameterIsNotNull(name, "name");
super();
this.id = id;
this.name = name;
}
public final int component1() {
return this.id;
}
@NotNull
public final String component2() {
return this.name;
}
@NotNull
public final Movie copy(int id, @NotNull String name) {
Intrinsics.checkParameterIsNotNull(name, "name");
return new Movie(id, name);
}
// $FF: synthetic method
// $FF: bridge method
@NotNull
public static Movie copy$default(Movie var0, int var1, String var2, int var3, Object var4) {
if ((var3 & 1) != 0) {
var1 = var0.id;
}
if ((var3 & 2) != 0) {
var2 = var0.name;
}
return var0.copy(var1, var2);
}
public String toString() {
return "Movie(id=" + this.id + ", name=" + this.name + ")";
}
public int hashCode() {
return this.id * 31 + (this.name != null ? this.name.hashCode() : 0);
}
public boolean equals(Object var1) {
if (this != var1) {
if (var1 instanceof Movie) {
Movie var2 = (Movie)var1;
if (this.id == var2.id && Intrinsics.areEqual(this.name, var2.name)) {
return true;
}
}
return false;
} else {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment