Skip 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.

== vs equals

Featured Replies

I'm wondering in this example, which would be more appropriate?

getGrandExchange().getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.FINISHED_SALE

or

getGrandExchange().getStatus(GrandExchange.Box.BOX_1).equals(GrandExchange.Status.FINISHED_SALE)

 

Edited by someguy567

20 hours ago, someguy567 said:

I'm wondering in this example, which would be more appropriate?


getGrandExchange().getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.FINISHED_SALE

or


getGrandExchange().getStatus(GrandExchange.Box.BOX_1).equals(GrandExchange.Status.FINISHED_SALE)

 

One should make it a practice to always use #equals. Even when one is in a situation where references have to be compared (==) for a custom Class, one should still override the #equals method for it to implement reference comparing.

^ This does not apply to primitives and constants though :) .

Edited by Eagle Scripts

Use == for primitives and constants
Use .equals() for everything else

GrandExchange.Status is an enum, and enum values are always constant (even if they for some reason are mutable), so here you should use '=='

15 hours ago, Alek said:

The following is not valid because String is an object:

String s = "abc";
 if(s == "abc") {
}

Those strings are literals actually; which are constant. '==' is valid :xboge:

Edited by FrostBug

16 hours ago, FrostBug said:

Use == for primitives and constants
Use .equals() for everything else

GrandExchange.Status is an enum, and enum values are always constant (even if they for some reason are mutable), so here you should use '=='

Those strings are literals actually; which are constant. '==' is valid :xboge:

I think the main reason why what Alek wrote is valid is because both those string objects point to the same object. Compiler is smart enough to see that "abc" is being used twice and instead of making 2 separate objects, it makes both variables point to one "abc" object.

(90%)

8 hours ago, dreameo said:

I think the main reason why what Alek wrote is valid is because both those string objects point to the same object. Compiler is smart enough to see that "abc" is being used twice and instead of making 2 separate objects, it makes both variables point to one "abc" object.

(90%)

Yes, constants as in the same object. Java uses whats called a String constant pool where all string literals are stored. When creating the second literal, the pool is checked, and a reference to the previously added literal is returned

On 11/8/2018 at 3:50 AM, FrostBug said:

Use == for primitives and constants
Use .equals() for everything else

GrandExchange.Status is an enum, and enum values are always constant (even if they for some reason are mutable), so here you should use '=='

Those strings are literals actually; which are constant. '==' is valid :xboge:

fake news!!! nice try CNN!

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

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.