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.

Difference bewtween exists() and !null?

Featured Replies

  • Author

What situation are you referring to? Not all classes define an exists method

I'm using this npc.exists(). I don't know to use exists() or != null. Or maybe even both if they are different?

I'm using this npc.exists(). I don't know to use exists() or != null. Or maybe even both if they are different?

They are indeed different.

npc != null is referred to as a "null check". npc.exists() is a call from an object through a variable.

 

npc is a "reference variable" - a variable used to "point" to an object. When a reference variable does not point to an object, it points to "null".

 

The object contains the actual exists() method, not the variable. If npc is not pointing to an object, it cannot properly call the method, resulting in a NullPointerException.

 

Unless you are 100% sure npc will not contain null, you do not need the null check. Although, if there's a possibility it will be null, you need the null check before you attempt to call npc.exists().

 

This is basic Object Orientation. If you'd like to know more, feel free to message me :) (don't be shy)

Edited by fixthissite

  • Author

They are indeed different.

npc != null is referred to as a "null check". npc.exists() is a call from an object through a variable.

 

npc is a "reference variable" - a variable used to "point" to an object. When a reference variable does not point to an object, it points to "null".

 

The object contains the actual exists() method, not the variable. If npc is not pointing to an object, it cannot properly call the method, resulting in a NullPointerException.

 

Unless you are 100% sure npc will not contain null, you do not need the null check. Although, if there's a possibility it will be null, you need the null check before you attempt to call npc.exists().

 

This is basic Object Orientation. If you'd like to know more, feel free to message me smile.png (don't be shy)

Thank you I appreciate the help :)

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.