Is Kotlin “pass-by-value” or “pass-by-reference”?
As I know Java is pass-by-value from this post. I am from Java background I wonder what Kotlin is using for passing values in between. Like in Extensions or Methods etc.
kotlin
|
show 1 more comment
As I know Java is pass-by-value from this post. I am from Java background I wonder what Kotlin is using for passing values in between. Like in Extensions or Methods etc.
kotlin
6
I think it's fair to say that everything works the same way as in Java.
– zsmb13
Jun 13 '17 at 7:33
i have read the differences between kotlin and java from various blogs, is there any kind of big internal change which needs to be covered?
– Rahul Khurana
Jun 13 '17 at 7:38
Probably not, Kotlin is compiled to bytecode in a pretty straightforward way in general.
– zsmb13
Jun 13 '17 at 7:40
Ok thanks i understand. I am curious to know why google has announced kotlin as first language for android
– Rahul Khurana
Jun 13 '17 at 7:42
@Pelocho consider converting your comment to an answer.
– Kirill Rakhman
Jun 13 '17 at 8:35
|
show 1 more comment
As I know Java is pass-by-value from this post. I am from Java background I wonder what Kotlin is using for passing values in between. Like in Extensions or Methods etc.
kotlin
As I know Java is pass-by-value from this post. I am from Java background I wonder what Kotlin is using for passing values in between. Like in Extensions or Methods etc.
kotlin
kotlin
edited Apr 20 at 12:28
asked Jun 13 '17 at 7:32
Rahul Khurana
3,00141641
3,00141641
6
I think it's fair to say that everything works the same way as in Java.
– zsmb13
Jun 13 '17 at 7:33
i have read the differences between kotlin and java from various blogs, is there any kind of big internal change which needs to be covered?
– Rahul Khurana
Jun 13 '17 at 7:38
Probably not, Kotlin is compiled to bytecode in a pretty straightforward way in general.
– zsmb13
Jun 13 '17 at 7:40
Ok thanks i understand. I am curious to know why google has announced kotlin as first language for android
– Rahul Khurana
Jun 13 '17 at 7:42
@Pelocho consider converting your comment to an answer.
– Kirill Rakhman
Jun 13 '17 at 8:35
|
show 1 more comment
6
I think it's fair to say that everything works the same way as in Java.
– zsmb13
Jun 13 '17 at 7:33
i have read the differences between kotlin and java from various blogs, is there any kind of big internal change which needs to be covered?
– Rahul Khurana
Jun 13 '17 at 7:38
Probably not, Kotlin is compiled to bytecode in a pretty straightforward way in general.
– zsmb13
Jun 13 '17 at 7:40
Ok thanks i understand. I am curious to know why google has announced kotlin as first language for android
– Rahul Khurana
Jun 13 '17 at 7:42
@Pelocho consider converting your comment to an answer.
– Kirill Rakhman
Jun 13 '17 at 8:35
6
6
I think it's fair to say that everything works the same way as in Java.
– zsmb13
Jun 13 '17 at 7:33
I think it's fair to say that everything works the same way as in Java.
– zsmb13
Jun 13 '17 at 7:33
i have read the differences between kotlin and java from various blogs, is there any kind of big internal change which needs to be covered?
– Rahul Khurana
Jun 13 '17 at 7:38
i have read the differences between kotlin and java from various blogs, is there any kind of big internal change which needs to be covered?
– Rahul Khurana
Jun 13 '17 at 7:38
Probably not, Kotlin is compiled to bytecode in a pretty straightforward way in general.
– zsmb13
Jun 13 '17 at 7:40
Probably not, Kotlin is compiled to bytecode in a pretty straightforward way in general.
– zsmb13
Jun 13 '17 at 7:40
Ok thanks i understand. I am curious to know why google has announced kotlin as first language for android
– Rahul Khurana
Jun 13 '17 at 7:42
Ok thanks i understand. I am curious to know why google has announced kotlin as first language for android
– Rahul Khurana
Jun 13 '17 at 7:42
@Pelocho consider converting your comment to an answer.
– Kirill Rakhman
Jun 13 '17 at 8:35
@Pelocho consider converting your comment to an answer.
– Kirill Rakhman
Jun 13 '17 at 8:35
|
show 1 more comment
3 Answers
3
active
oldest
votes
Every time I hear about the "pass-by-value" vs "pass-by-reference" Java debate I always think the same. The answer I give: "Java passes a copy (pass-by-value) of the reference (pass-by-reference)". So everyone is happy. I would say Kotlin does the same as is JVM based
add a comment |
The semantics is identical to Java.
In Java, when you have an instance of an object, and you pass it to a method, that method can change the state of that object, and when the method is done, the changes would have been applied to the object at the call site.
The same applies in Kotlin.
add a comment |
In Java primitive types like int, float, double, boolean are passed to a method by value, if you modify them inside the receiver method they doesn't change into the calling method. But if the property/variable type isn't a primitive, like arrays of primitives or other classes when they are changed inside the method that receive them as parameter they also change in the caller method.
But with Kotlin nothing seems to be primitive, so I think all is passed by reference.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44515031%2fis-kotlin-pass-by-value-or-pass-by-reference%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Every time I hear about the "pass-by-value" vs "pass-by-reference" Java debate I always think the same. The answer I give: "Java passes a copy (pass-by-value) of the reference (pass-by-reference)". So everyone is happy. I would say Kotlin does the same as is JVM based
add a comment |
Every time I hear about the "pass-by-value" vs "pass-by-reference" Java debate I always think the same. The answer I give: "Java passes a copy (pass-by-value) of the reference (pass-by-reference)". So everyone is happy. I would say Kotlin does the same as is JVM based
add a comment |
Every time I hear about the "pass-by-value" vs "pass-by-reference" Java debate I always think the same. The answer I give: "Java passes a copy (pass-by-value) of the reference (pass-by-reference)". So everyone is happy. I would say Kotlin does the same as is JVM based
Every time I hear about the "pass-by-value" vs "pass-by-reference" Java debate I always think the same. The answer I give: "Java passes a copy (pass-by-value) of the reference (pass-by-reference)". So everyone is happy. I would say Kotlin does the same as is JVM based
answered Jun 13 '17 at 8:41
Pelocho
4,09821332
4,09821332
add a comment |
add a comment |
The semantics is identical to Java.
In Java, when you have an instance of an object, and you pass it to a method, that method can change the state of that object, and when the method is done, the changes would have been applied to the object at the call site.
The same applies in Kotlin.
add a comment |
The semantics is identical to Java.
In Java, when you have an instance of an object, and you pass it to a method, that method can change the state of that object, and when the method is done, the changes would have been applied to the object at the call site.
The same applies in Kotlin.
add a comment |
The semantics is identical to Java.
In Java, when you have an instance of an object, and you pass it to a method, that method can change the state of that object, and when the method is done, the changes would have been applied to the object at the call site.
The same applies in Kotlin.
The semantics is identical to Java.
In Java, when you have an instance of an object, and you pass it to a method, that method can change the state of that object, and when the method is done, the changes would have been applied to the object at the call site.
The same applies in Kotlin.
answered Jun 13 '17 at 10:29
hasen
81.7k57163211
81.7k57163211
add a comment |
add a comment |
In Java primitive types like int, float, double, boolean are passed to a method by value, if you modify them inside the receiver method they doesn't change into the calling method. But if the property/variable type isn't a primitive, like arrays of primitives or other classes when they are changed inside the method that receive them as parameter they also change in the caller method.
But with Kotlin nothing seems to be primitive, so I think all is passed by reference.
add a comment |
In Java primitive types like int, float, double, boolean are passed to a method by value, if you modify them inside the receiver method they doesn't change into the calling method. But if the property/variable type isn't a primitive, like arrays of primitives or other classes when they are changed inside the method that receive them as parameter they also change in the caller method.
But with Kotlin nothing seems to be primitive, so I think all is passed by reference.
add a comment |
In Java primitive types like int, float, double, boolean are passed to a method by value, if you modify them inside the receiver method they doesn't change into the calling method. But if the property/variable type isn't a primitive, like arrays of primitives or other classes when they are changed inside the method that receive them as parameter they also change in the caller method.
But with Kotlin nothing seems to be primitive, so I think all is passed by reference.
In Java primitive types like int, float, double, boolean are passed to a method by value, if you modify them inside the receiver method they doesn't change into the calling method. But if the property/variable type isn't a primitive, like arrays of primitives or other classes when they are changed inside the method that receive them as parameter they also change in the caller method.
But with Kotlin nothing seems to be primitive, so I think all is passed by reference.
answered Nov 12 at 3:58
user2604769
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44515031%2fis-kotlin-pass-by-value-or-pass-by-reference%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
I think it's fair to say that everything works the same way as in Java.
– zsmb13
Jun 13 '17 at 7:33
i have read the differences between kotlin and java from various blogs, is there any kind of big internal change which needs to be covered?
– Rahul Khurana
Jun 13 '17 at 7:38
Probably not, Kotlin is compiled to bytecode in a pretty straightforward way in general.
– zsmb13
Jun 13 '17 at 7:40
Ok thanks i understand. I am curious to know why google has announced kotlin as first language for android
– Rahul Khurana
Jun 13 '17 at 7:42
@Pelocho consider converting your comment to an answer.
– Kirill Rakhman
Jun 13 '17 at 8:35