Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Pass-by-Value vs Pass-by-reference (Java)

Featured Replies

....

The problem we're facing here is statements like In Java, Objects are passed by reference, and primitives are passed by value. This is half incorrect. Everyone can easily agree that primitives are passed by value; there's no such thing in Java as a pointer/reference to a primitive. However, Objects are not passed by reference. A correct statement would be Object references are passed by value. This may seem like splitting hairs, bit it is far from it. There is a world of difference in meaning. The following examples should help make the distinction.

...

 

Interesting article:

 

http://javadude.com/articles/passbyvalue.htm

  • 2 weeks later...

Java uses quite a few tricks to achieve what other languages have while still being user-friendly, and this is a great example. Although, after reading the article, I was kinda confused.

For anyone having troubles understanding, if objects were pass-by-reference, this would be possible:

void method(String string) {
    string = "second";
}

String string = "first";
method(string);
System.out.println(string); //prints "second"

Rather than passing the actual reference to that object, a new reference is created (the formal parameter), which then references the object.

So saying object references are pass by value is not true, since a reference value is a pointer to the object, and passing the reference value (pointer) is passing by reference. If you wanna get literal with it, object identities are (currently) pass by value.

Another thing that confuses some developers is how generics are a compile time illusion, and all generic types are converted to Object (type erasure) once compiled. This is why you cannot have "void method(List<String>)" and overload it with "void method(List<Integer>)", since both compile to the same after erasure.

Edited by fixthissite

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.