Jump to content

Java int help


Guest

Recommended Posts

Is there any way to make Java pass ints by reference and not value?

Not just ints, but doubles, floats, short, byte, long, etc.

^ All of these pass by value, not reference.

Link to comment
Share on other sites

7 minutes ago, Noidlox said:

Is there any way to make Java pass ints by reference and not value?

Not just ints, but doubles, floats, short, byte, long, etc.

^ All of these pass by value, not reference.

It's not really do-able in Java.

EDIT: You could pass an int[].

Edited by Container
Link to comment
Share on other sites

8 hours ago, Vilius said:

Java is a pass by value and Integer is immutable. So no, you cannot pass an ints reference in the arguments of a method.

Makes sense. Thank you

9 hours ago, Container said:

It's not really do-able in Java.

EDIT: You could pass an int[].

With arrays you can.... Interesting

Link to comment
Share on other sites

1 hour ago, Botre said:

Just... wrap it in an object.

 

public class MutableInteger {  
  
  private int value; 
  
  public int getValue() {
    return value;
  }  
  
  public void setValue(int value) { 
    this.value = value;
  } 
  
}

Getters and setters to the rescue.

I'm writing this down. Thank you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...