Please help me translate kotlin to java [closed]
I don't know how to translate this kotlin line into java.
data class ContactData(val name: String? = "", val online: Boolean = false)
This is what I tried, but I'm not sure.
public final class ContactData {
private String name = "";
private boolean online = false;
public final String getName() {
return name;
}
public final boolean getOnline() {
return online;
}
ContactData(String name, boolean online) {
this.name = name;
this.online = online;
}
public final String name() {
return this.name;
}
public final boolean online() {
return this.online;
}
}
please help me to fix it
kotlin
closed as off-topic by Stephen C, cнŝdk, Ahmad, Zabuza, shmosel Nov 22 '18 at 8:32
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – cнŝdk, Zabuza
If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
I don't know how to translate this kotlin line into java.
data class ContactData(val name: String? = "", val online: Boolean = false)
This is what I tried, but I'm not sure.
public final class ContactData {
private String name = "";
private boolean online = false;
public final String getName() {
return name;
}
public final boolean getOnline() {
return online;
}
ContactData(String name, boolean online) {
this.name = name;
this.online = online;
}
public final String name() {
return this.name;
}
public final boolean online() {
return this.online;
}
}
please help me to fix it
kotlin
closed as off-topic by Stephen C, cнŝdk, Ahmad, Zabuza, shmosel Nov 22 '18 at 8:32
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – cнŝdk, Zabuza
If this question can be reworded to fit the rules in the help center, please edit the question.
4
Besides duplicating your getters, what exactly is the problem?
– Mureinik
Nov 22 '18 at 7:25
1
Welcome to Stack Overflow! Please take the tour and visit our help center to learn what kinds of questions are appropriate for this site. If you can edit your question to fit the requirements of this site, please do so.
– Joe C
Nov 22 '18 at 7:41
1
Please provide exact and detailed information on your actual problem. Explain what does not work, include error messages and explain with which part you have difficulties. Also make sure to do proper research before posting on StackOverflow, thanks.
– Zabuza
Nov 22 '18 at 8:06
1
at least in Intellij you can show the Kotlin bytecode and from there you can choose "Decompile" to get the decompiled Java source. That code will then probably not work as is, but you should find everything you are interested in...
– Roland
Nov 22 '18 at 8:13
Thanks for your response, sorry if I don't follow the post rules, I will fix it :)
– Ady Irawan
Nov 22 '18 at 8:14
|
show 2 more comments
I don't know how to translate this kotlin line into java.
data class ContactData(val name: String? = "", val online: Boolean = false)
This is what I tried, but I'm not sure.
public final class ContactData {
private String name = "";
private boolean online = false;
public final String getName() {
return name;
}
public final boolean getOnline() {
return online;
}
ContactData(String name, boolean online) {
this.name = name;
this.online = online;
}
public final String name() {
return this.name;
}
public final boolean online() {
return this.online;
}
}
please help me to fix it
kotlin
I don't know how to translate this kotlin line into java.
data class ContactData(val name: String? = "", val online: Boolean = false)
This is what I tried, but I'm not sure.
public final class ContactData {
private String name = "";
private boolean online = false;
public final String getName() {
return name;
}
public final boolean getOnline() {
return online;
}
ContactData(String name, boolean online) {
this.name = name;
this.online = online;
}
public final String name() {
return this.name;
}
public final boolean online() {
return this.online;
}
}
please help me to fix it
kotlin
kotlin
edited Nov 22 '18 at 18:38
Jayson Minard
40.4k17114174
40.4k17114174
asked Nov 22 '18 at 7:24


Ady IrawanAdy Irawan
1
1
closed as off-topic by Stephen C, cнŝdk, Ahmad, Zabuza, shmosel Nov 22 '18 at 8:32
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – cнŝdk, Zabuza
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Stephen C, cнŝdk, Ahmad, Zabuza, shmosel Nov 22 '18 at 8:32
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – cнŝdk, Zabuza
If this question can be reworded to fit the rules in the help center, please edit the question.
4
Besides duplicating your getters, what exactly is the problem?
– Mureinik
Nov 22 '18 at 7:25
1
Welcome to Stack Overflow! Please take the tour and visit our help center to learn what kinds of questions are appropriate for this site. If you can edit your question to fit the requirements of this site, please do so.
– Joe C
Nov 22 '18 at 7:41
1
Please provide exact and detailed information on your actual problem. Explain what does not work, include error messages and explain with which part you have difficulties. Also make sure to do proper research before posting on StackOverflow, thanks.
– Zabuza
Nov 22 '18 at 8:06
1
at least in Intellij you can show the Kotlin bytecode and from there you can choose "Decompile" to get the decompiled Java source. That code will then probably not work as is, but you should find everything you are interested in...
– Roland
Nov 22 '18 at 8:13
Thanks for your response, sorry if I don't follow the post rules, I will fix it :)
– Ady Irawan
Nov 22 '18 at 8:14
|
show 2 more comments
4
Besides duplicating your getters, what exactly is the problem?
– Mureinik
Nov 22 '18 at 7:25
1
Welcome to Stack Overflow! Please take the tour and visit our help center to learn what kinds of questions are appropriate for this site. If you can edit your question to fit the requirements of this site, please do so.
– Joe C
Nov 22 '18 at 7:41
1
Please provide exact and detailed information on your actual problem. Explain what does not work, include error messages and explain with which part you have difficulties. Also make sure to do proper research before posting on StackOverflow, thanks.
– Zabuza
Nov 22 '18 at 8:06
1
at least in Intellij you can show the Kotlin bytecode and from there you can choose "Decompile" to get the decompiled Java source. That code will then probably not work as is, but you should find everything you are interested in...
– Roland
Nov 22 '18 at 8:13
Thanks for your response, sorry if I don't follow the post rules, I will fix it :)
– Ady Irawan
Nov 22 '18 at 8:14
4
4
Besides duplicating your getters, what exactly is the problem?
– Mureinik
Nov 22 '18 at 7:25
Besides duplicating your getters, what exactly is the problem?
– Mureinik
Nov 22 '18 at 7:25
1
1
Welcome to Stack Overflow! Please take the tour and visit our help center to learn what kinds of questions are appropriate for this site. If you can edit your question to fit the requirements of this site, please do so.
– Joe C
Nov 22 '18 at 7:41
Welcome to Stack Overflow! Please take the tour and visit our help center to learn what kinds of questions are appropriate for this site. If you can edit your question to fit the requirements of this site, please do so.
– Joe C
Nov 22 '18 at 7:41
1
1
Please provide exact and detailed information on your actual problem. Explain what does not work, include error messages and explain with which part you have difficulties. Also make sure to do proper research before posting on StackOverflow, thanks.
– Zabuza
Nov 22 '18 at 8:06
Please provide exact and detailed information on your actual problem. Explain what does not work, include error messages and explain with which part you have difficulties. Also make sure to do proper research before posting on StackOverflow, thanks.
– Zabuza
Nov 22 '18 at 8:06
1
1
at least in Intellij you can show the Kotlin bytecode and from there you can choose "Decompile" to get the decompiled Java source. That code will then probably not work as is, but you should find everything you are interested in...
– Roland
Nov 22 '18 at 8:13
at least in Intellij you can show the Kotlin bytecode and from there you can choose "Decompile" to get the decompiled Java source. That code will then probably not work as is, but you should find everything you are interested in...
– Roland
Nov 22 '18 at 8:13
Thanks for your response, sorry if I don't follow the post rules, I will fix it :)
– Ady Irawan
Nov 22 '18 at 8:14
Thanks for your response, sorry if I don't follow the post rules, I will fix it :)
– Ady Irawan
Nov 22 '18 at 8:14
|
show 2 more comments
2 Answers
2
active
oldest
votes
I would say it is going to be something like this:
import org.jetbrains.annotations.NotNull;
public class ContactDataa {
@NotNull
private final String name;
private final boolean online;
public ContactDataa() {
this("", false);
}
public ContactDataa(final String name) {
this(name, false);
}
public ContactDataa(final boolean online) {
this("", online);
}
public ContactDataa(final String name, final boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
this.name = name;
this.online = online;
}
public String getName() {
return name;
}
public boolean isOnline() {
return online;
}
public String component1() {
return name;
}
public boolean component2() {
return online;
}
@NotNull
public final ContactData copy(@NotNull String name, boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(@NotNull String name) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(boolean online) {
return new ContactData(name, online);
}
@NotNull
public final ContactData copy() {
return new ContactData(name, online);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContactDataa that = (ContactDataa) o;
if (online != that.online) return false;
return name != null ? name.equals(that.name) : that.name == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (online ? 1 : 0);
return result;
}
@Override
public String toString() {
return "ContactDataa{" +
"name='" + name + ''' +
", online=" + online +
'}';
}
}
Problem here is a complete intertop with other Kotlin's classes. Also, if you use Intellij IDEA or Android Studio, you can just get Kotlin bytecode and decompile it to Java.
Will it really be this much? I've tried using decompiler, and it looks like that isn't what I'm looking for, by the way, thank you for the response
– Ady Irawan
Nov 22 '18 at 8:22
1
yes, it will be that much... data classes deliverhashCode
,toString
,equals
,copy
, etc. pp... that's why they are so popular... what did you expect? Please also read up about data classes in the Kotlin reference...
– Roland
Nov 22 '18 at 8:26
Kotlin generates very specific methods and adds specific parameters for data classes' methods, and thus compiles all the invocations of these methods from the outside in a transforming way. If you want complete intertop with Kotlin's classes - decompiler will help. I've just created a Java's copy that is the same on how this class is used, not by how it is compiled into bytecode.
– Andrey Ilyunin
Nov 22 '18 at 8:26
ahhh ok thank you very much, now i understand
– Ady Irawan
Nov 22 '18 at 8:29
@Roland I just want to translate this source into java but I can't find the right way to translate FirebaseData.kt files
– Ady Irawan
Nov 22 '18 at 8:33
add a comment |
If you want the same behaviour as the default values in Kotlin you need three extra constructors:
ContactData() {
}
ContactData(String name) {
this.name = name;
}
ContactData(boolean online) {
this.online = online;
}
Also you have to override hashCode() and equals(), toString and copy() and the component functions see https://kotlinlang.org/docs/reference/data-classes.html.
ContactData(String name, boolean online) { this.name = name; this.online = online; } hemm, is this different?
– Ady Irawan
Nov 22 '18 at 8:19
obviously a constructor with different arguments is different. You need all four if you want to replicate the behaviour of the default parameters.
– leonardkraemer
Nov 22 '18 at 8:30
ahh ok thank you very much :)
– Ady Irawan
Nov 22 '18 at 8:37
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would say it is going to be something like this:
import org.jetbrains.annotations.NotNull;
public class ContactDataa {
@NotNull
private final String name;
private final boolean online;
public ContactDataa() {
this("", false);
}
public ContactDataa(final String name) {
this(name, false);
}
public ContactDataa(final boolean online) {
this("", online);
}
public ContactDataa(final String name, final boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
this.name = name;
this.online = online;
}
public String getName() {
return name;
}
public boolean isOnline() {
return online;
}
public String component1() {
return name;
}
public boolean component2() {
return online;
}
@NotNull
public final ContactData copy(@NotNull String name, boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(@NotNull String name) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(boolean online) {
return new ContactData(name, online);
}
@NotNull
public final ContactData copy() {
return new ContactData(name, online);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContactDataa that = (ContactDataa) o;
if (online != that.online) return false;
return name != null ? name.equals(that.name) : that.name == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (online ? 1 : 0);
return result;
}
@Override
public String toString() {
return "ContactDataa{" +
"name='" + name + ''' +
", online=" + online +
'}';
}
}
Problem here is a complete intertop with other Kotlin's classes. Also, if you use Intellij IDEA or Android Studio, you can just get Kotlin bytecode and decompile it to Java.
Will it really be this much? I've tried using decompiler, and it looks like that isn't what I'm looking for, by the way, thank you for the response
– Ady Irawan
Nov 22 '18 at 8:22
1
yes, it will be that much... data classes deliverhashCode
,toString
,equals
,copy
, etc. pp... that's why they are so popular... what did you expect? Please also read up about data classes in the Kotlin reference...
– Roland
Nov 22 '18 at 8:26
Kotlin generates very specific methods and adds specific parameters for data classes' methods, and thus compiles all the invocations of these methods from the outside in a transforming way. If you want complete intertop with Kotlin's classes - decompiler will help. I've just created a Java's copy that is the same on how this class is used, not by how it is compiled into bytecode.
– Andrey Ilyunin
Nov 22 '18 at 8:26
ahhh ok thank you very much, now i understand
– Ady Irawan
Nov 22 '18 at 8:29
@Roland I just want to translate this source into java but I can't find the right way to translate FirebaseData.kt files
– Ady Irawan
Nov 22 '18 at 8:33
add a comment |
I would say it is going to be something like this:
import org.jetbrains.annotations.NotNull;
public class ContactDataa {
@NotNull
private final String name;
private final boolean online;
public ContactDataa() {
this("", false);
}
public ContactDataa(final String name) {
this(name, false);
}
public ContactDataa(final boolean online) {
this("", online);
}
public ContactDataa(final String name, final boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
this.name = name;
this.online = online;
}
public String getName() {
return name;
}
public boolean isOnline() {
return online;
}
public String component1() {
return name;
}
public boolean component2() {
return online;
}
@NotNull
public final ContactData copy(@NotNull String name, boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(@NotNull String name) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(boolean online) {
return new ContactData(name, online);
}
@NotNull
public final ContactData copy() {
return new ContactData(name, online);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContactDataa that = (ContactDataa) o;
if (online != that.online) return false;
return name != null ? name.equals(that.name) : that.name == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (online ? 1 : 0);
return result;
}
@Override
public String toString() {
return "ContactDataa{" +
"name='" + name + ''' +
", online=" + online +
'}';
}
}
Problem here is a complete intertop with other Kotlin's classes. Also, if you use Intellij IDEA or Android Studio, you can just get Kotlin bytecode and decompile it to Java.
Will it really be this much? I've tried using decompiler, and it looks like that isn't what I'm looking for, by the way, thank you for the response
– Ady Irawan
Nov 22 '18 at 8:22
1
yes, it will be that much... data classes deliverhashCode
,toString
,equals
,copy
, etc. pp... that's why they are so popular... what did you expect? Please also read up about data classes in the Kotlin reference...
– Roland
Nov 22 '18 at 8:26
Kotlin generates very specific methods and adds specific parameters for data classes' methods, and thus compiles all the invocations of these methods from the outside in a transforming way. If you want complete intertop with Kotlin's classes - decompiler will help. I've just created a Java's copy that is the same on how this class is used, not by how it is compiled into bytecode.
– Andrey Ilyunin
Nov 22 '18 at 8:26
ahhh ok thank you very much, now i understand
– Ady Irawan
Nov 22 '18 at 8:29
@Roland I just want to translate this source into java but I can't find the right way to translate FirebaseData.kt files
– Ady Irawan
Nov 22 '18 at 8:33
add a comment |
I would say it is going to be something like this:
import org.jetbrains.annotations.NotNull;
public class ContactDataa {
@NotNull
private final String name;
private final boolean online;
public ContactDataa() {
this("", false);
}
public ContactDataa(final String name) {
this(name, false);
}
public ContactDataa(final boolean online) {
this("", online);
}
public ContactDataa(final String name, final boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
this.name = name;
this.online = online;
}
public String getName() {
return name;
}
public boolean isOnline() {
return online;
}
public String component1() {
return name;
}
public boolean component2() {
return online;
}
@NotNull
public final ContactData copy(@NotNull String name, boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(@NotNull String name) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(boolean online) {
return new ContactData(name, online);
}
@NotNull
public final ContactData copy() {
return new ContactData(name, online);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContactDataa that = (ContactDataa) o;
if (online != that.online) return false;
return name != null ? name.equals(that.name) : that.name == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (online ? 1 : 0);
return result;
}
@Override
public String toString() {
return "ContactDataa{" +
"name='" + name + ''' +
", online=" + online +
'}';
}
}
Problem here is a complete intertop with other Kotlin's classes. Also, if you use Intellij IDEA or Android Studio, you can just get Kotlin bytecode and decompile it to Java.
I would say it is going to be something like this:
import org.jetbrains.annotations.NotNull;
public class ContactDataa {
@NotNull
private final String name;
private final boolean online;
public ContactDataa() {
this("", false);
}
public ContactDataa(final String name) {
this(name, false);
}
public ContactDataa(final boolean online) {
this("", online);
}
public ContactDataa(final String name, final boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
this.name = name;
this.online = online;
}
public String getName() {
return name;
}
public boolean isOnline() {
return online;
}
public String component1() {
return name;
}
public boolean component2() {
return online;
}
@NotNull
public final ContactData copy(@NotNull String name, boolean online) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(@NotNull String name) {
if (name == null) {
throw new IllegalArgumentException();
}
return new ContactData(name, online);
}
@NotNull
public final ContactData copy(boolean online) {
return new ContactData(name, online);
}
@NotNull
public final ContactData copy() {
return new ContactData(name, online);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContactDataa that = (ContactDataa) o;
if (online != that.online) return false;
return name != null ? name.equals(that.name) : that.name == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (online ? 1 : 0);
return result;
}
@Override
public String toString() {
return "ContactDataa{" +
"name='" + name + ''' +
", online=" + online +
'}';
}
}
Problem here is a complete intertop with other Kotlin's classes. Also, if you use Intellij IDEA or Android Studio, you can just get Kotlin bytecode and decompile it to Java.
edited Nov 22 '18 at 8:29
answered Nov 22 '18 at 8:04


Andrey IlyuninAndrey Ilyunin
1,318220
1,318220
Will it really be this much? I've tried using decompiler, and it looks like that isn't what I'm looking for, by the way, thank you for the response
– Ady Irawan
Nov 22 '18 at 8:22
1
yes, it will be that much... data classes deliverhashCode
,toString
,equals
,copy
, etc. pp... that's why they are so popular... what did you expect? Please also read up about data classes in the Kotlin reference...
– Roland
Nov 22 '18 at 8:26
Kotlin generates very specific methods and adds specific parameters for data classes' methods, and thus compiles all the invocations of these methods from the outside in a transforming way. If you want complete intertop with Kotlin's classes - decompiler will help. I've just created a Java's copy that is the same on how this class is used, not by how it is compiled into bytecode.
– Andrey Ilyunin
Nov 22 '18 at 8:26
ahhh ok thank you very much, now i understand
– Ady Irawan
Nov 22 '18 at 8:29
@Roland I just want to translate this source into java but I can't find the right way to translate FirebaseData.kt files
– Ady Irawan
Nov 22 '18 at 8:33
add a comment |
Will it really be this much? I've tried using decompiler, and it looks like that isn't what I'm looking for, by the way, thank you for the response
– Ady Irawan
Nov 22 '18 at 8:22
1
yes, it will be that much... data classes deliverhashCode
,toString
,equals
,copy
, etc. pp... that's why they are so popular... what did you expect? Please also read up about data classes in the Kotlin reference...
– Roland
Nov 22 '18 at 8:26
Kotlin generates very specific methods and adds specific parameters for data classes' methods, and thus compiles all the invocations of these methods from the outside in a transforming way. If you want complete intertop with Kotlin's classes - decompiler will help. I've just created a Java's copy that is the same on how this class is used, not by how it is compiled into bytecode.
– Andrey Ilyunin
Nov 22 '18 at 8:26
ahhh ok thank you very much, now i understand
– Ady Irawan
Nov 22 '18 at 8:29
@Roland I just want to translate this source into java but I can't find the right way to translate FirebaseData.kt files
– Ady Irawan
Nov 22 '18 at 8:33
Will it really be this much? I've tried using decompiler, and it looks like that isn't what I'm looking for, by the way, thank you for the response
– Ady Irawan
Nov 22 '18 at 8:22
Will it really be this much? I've tried using decompiler, and it looks like that isn't what I'm looking for, by the way, thank you for the response
– Ady Irawan
Nov 22 '18 at 8:22
1
1
yes, it will be that much... data classes deliver
hashCode
, toString
, equals
, copy
, etc. pp... that's why they are so popular... what did you expect? Please also read up about data classes in the Kotlin reference...– Roland
Nov 22 '18 at 8:26
yes, it will be that much... data classes deliver
hashCode
, toString
, equals
, copy
, etc. pp... that's why they are so popular... what did you expect? Please also read up about data classes in the Kotlin reference...– Roland
Nov 22 '18 at 8:26
Kotlin generates very specific methods and adds specific parameters for data classes' methods, and thus compiles all the invocations of these methods from the outside in a transforming way. If you want complete intertop with Kotlin's classes - decompiler will help. I've just created a Java's copy that is the same on how this class is used, not by how it is compiled into bytecode.
– Andrey Ilyunin
Nov 22 '18 at 8:26
Kotlin generates very specific methods and adds specific parameters for data classes' methods, and thus compiles all the invocations of these methods from the outside in a transforming way. If you want complete intertop with Kotlin's classes - decompiler will help. I've just created a Java's copy that is the same on how this class is used, not by how it is compiled into bytecode.
– Andrey Ilyunin
Nov 22 '18 at 8:26
ahhh ok thank you very much, now i understand
– Ady Irawan
Nov 22 '18 at 8:29
ahhh ok thank you very much, now i understand
– Ady Irawan
Nov 22 '18 at 8:29
@Roland I just want to translate this source into java but I can't find the right way to translate FirebaseData.kt files
– Ady Irawan
Nov 22 '18 at 8:33
@Roland I just want to translate this source into java but I can't find the right way to translate FirebaseData.kt files
– Ady Irawan
Nov 22 '18 at 8:33
add a comment |
If you want the same behaviour as the default values in Kotlin you need three extra constructors:
ContactData() {
}
ContactData(String name) {
this.name = name;
}
ContactData(boolean online) {
this.online = online;
}
Also you have to override hashCode() and equals(), toString and copy() and the component functions see https://kotlinlang.org/docs/reference/data-classes.html.
ContactData(String name, boolean online) { this.name = name; this.online = online; } hemm, is this different?
– Ady Irawan
Nov 22 '18 at 8:19
obviously a constructor with different arguments is different. You need all four if you want to replicate the behaviour of the default parameters.
– leonardkraemer
Nov 22 '18 at 8:30
ahh ok thank you very much :)
– Ady Irawan
Nov 22 '18 at 8:37
add a comment |
If you want the same behaviour as the default values in Kotlin you need three extra constructors:
ContactData() {
}
ContactData(String name) {
this.name = name;
}
ContactData(boolean online) {
this.online = online;
}
Also you have to override hashCode() and equals(), toString and copy() and the component functions see https://kotlinlang.org/docs/reference/data-classes.html.
ContactData(String name, boolean online) { this.name = name; this.online = online; } hemm, is this different?
– Ady Irawan
Nov 22 '18 at 8:19
obviously a constructor with different arguments is different. You need all four if you want to replicate the behaviour of the default parameters.
– leonardkraemer
Nov 22 '18 at 8:30
ahh ok thank you very much :)
– Ady Irawan
Nov 22 '18 at 8:37
add a comment |
If you want the same behaviour as the default values in Kotlin you need three extra constructors:
ContactData() {
}
ContactData(String name) {
this.name = name;
}
ContactData(boolean online) {
this.online = online;
}
Also you have to override hashCode() and equals(), toString and copy() and the component functions see https://kotlinlang.org/docs/reference/data-classes.html.
If you want the same behaviour as the default values in Kotlin you need three extra constructors:
ContactData() {
}
ContactData(String name) {
this.name = name;
}
ContactData(boolean online) {
this.online = online;
}
Also you have to override hashCode() and equals(), toString and copy() and the component functions see https://kotlinlang.org/docs/reference/data-classes.html.
edited Nov 22 '18 at 7:46
answered Nov 22 '18 at 7:40
leonardkraemerleonardkraemer
3,45111532
3,45111532
ContactData(String name, boolean online) { this.name = name; this.online = online; } hemm, is this different?
– Ady Irawan
Nov 22 '18 at 8:19
obviously a constructor with different arguments is different. You need all four if you want to replicate the behaviour of the default parameters.
– leonardkraemer
Nov 22 '18 at 8:30
ahh ok thank you very much :)
– Ady Irawan
Nov 22 '18 at 8:37
add a comment |
ContactData(String name, boolean online) { this.name = name; this.online = online; } hemm, is this different?
– Ady Irawan
Nov 22 '18 at 8:19
obviously a constructor with different arguments is different. You need all four if you want to replicate the behaviour of the default parameters.
– leonardkraemer
Nov 22 '18 at 8:30
ahh ok thank you very much :)
– Ady Irawan
Nov 22 '18 at 8:37
ContactData(String name, boolean online) { this.name = name; this.online = online; } hemm, is this different?
– Ady Irawan
Nov 22 '18 at 8:19
ContactData(String name, boolean online) { this.name = name; this.online = online; } hemm, is this different?
– Ady Irawan
Nov 22 '18 at 8:19
obviously a constructor with different arguments is different. You need all four if you want to replicate the behaviour of the default parameters.
– leonardkraemer
Nov 22 '18 at 8:30
obviously a constructor with different arguments is different. You need all four if you want to replicate the behaviour of the default parameters.
– leonardkraemer
Nov 22 '18 at 8:30
ahh ok thank you very much :)
– Ady Irawan
Nov 22 '18 at 8:37
ahh ok thank you very much :)
– Ady Irawan
Nov 22 '18 at 8:37
add a comment |
4
Besides duplicating your getters, what exactly is the problem?
– Mureinik
Nov 22 '18 at 7:25
1
Welcome to Stack Overflow! Please take the tour and visit our help center to learn what kinds of questions are appropriate for this site. If you can edit your question to fit the requirements of this site, please do so.
– Joe C
Nov 22 '18 at 7:41
1
Please provide exact and detailed information on your actual problem. Explain what does not work, include error messages and explain with which part you have difficulties. Also make sure to do proper research before posting on StackOverflow, thanks.
– Zabuza
Nov 22 '18 at 8:06
1
at least in Intellij you can show the Kotlin bytecode and from there you can choose "Decompile" to get the decompiled Java source. That code will then probably not work as is, but you should find everything you are interested in...
– Roland
Nov 22 '18 at 8:13
Thanks for your response, sorry if I don't follow the post rules, I will fix it :)
– Ady Irawan
Nov 22 '18 at 8:14