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.

this keyword in constructor

Featured Replies

So I'm trying to add a new task to an ArrayList or rather create a new task.

tasks.add(new DropTask(this));

What I don't get is what the keyword this does here. I've only seen "this" used in methods to differenciate between the local variable and the instance variable.

 

Might be worth adding that the constructor in the DropTask class looks like this: public DropTask(MethodProvider api) { super(api);   }

13 minutes ago, Jammer said:

So I'm trying to add a new task to an ArrayList or rather create a new task.

tasks.add(new DropTask(this));

What I don't get is what the keyword this does here. I've only seen "this" used in methods to differenciate between the local variable and the instance variable.

 

Might be worth adding that the constructor in the DropTask class looks like this: public DropTask(MethodProvider api) { super(api);   }

 

Consider reading this https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

Essentially all it is doing is passing a reference to the current instance (which is of type MethodProvider) as a parameter to the constructor of DropTask

 

An alternative method, instead of passing around a instance of MethodProvider to access the API, would be to just make your other classes extend MethodProvider, and then exchangeContext:

 

public class SomeScript extends Script {

    SomeOtherClass someOtherClass;
  
    @Override
    public void onStart() {
        someOtherClass = new SomeOtherClass();
        someOtherClass.exchangeContext(getBot());
    }
}

class SomeOtherClass extends MethodProvider {
  
}

 

Edited by Explv

If you're using just 'this', then it's referencing the instance of the class.

class Hi{
  
  Hi thisCurrentObject = this;
  
  Hi(){}
  
}

Other times of using this is for ambiguity between local params and params taken from a method,constructor... w.e 

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.