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.

Some Java questions

Featured Replies

I have a few questions about Java.

 

  1.  When should I declare a method as "static"? I tried looking it up but I don't quite understand
  2.  What does it mean when Intellij tells me I am making an "unchecked call"?
  3.  At what point does it make more sense to create a separate class rather than use enum's

If you need to see my script to make sense of any of the above questions, let me know and I'll post it

 

Thanks for your help!

static - means that a method is not inherent to a specific instance of the class

 

e.g. 

 

class V {

    static void x() {

    }

}

 

you would call V.x() instead of new V().x() because it does not need an instance to run the method. think of it as something unrelated to the actual instantiated object, but rather an added functionality to the class itself.

 

unchecked call - not sure, maybe someone that uses intellij can respond

 

make a separate class vs. enums - depends on what is easiest and/or more organized and logical. both have their benefits.

 

 

  1.  When should I declare a method as "static"? I tried looking it up but I don't quite understand
  2.  What does it mean when Intellij tells me I am making an "unchecked call"?
  3.  At what point does it make more sense to create a separate class rather than use enum's

 

1. A member (Method or data field) should be declared static when you want it to be a member of the class rather than a member of an instance of the class. For example, if we had an object called Ball, it has all of its internal object information (Size, bounciness, etc.). We might also want information such as how many Balls there are. A single ball object doesn't have the scope to see how many other balls there are, so instead, we might have a static counter to hold this information, which we can access through Ball.getCount(). This might help.

 

2. Might need to see the code to tell, usually you get them when you aren't handling generics correctly, but there might be cases I don't know about.

 

3. Not entirely sure what you mean by this. I assume you mean splitting functionality into different classes rather than putting all your functionality into a single class. There isn't really a definite point, it's more of a "feel" thing. If you feel like your code is getting difficult to manage, split it up. OO programming tells you that each class should perform a discrete task.

of a young Steve Jobs talking about the OO approach, maybe it will help you in understanding when to divy up tasks.

Edited by BoysNoize

Static just means you are not instantiating that object. Non-static means that you will be instantiating that object.

So when you make a static method, it means everything in that method cannot be created. Let's say you have a public class that isn't static. 

You could go classname varname = new classname(); 

 

varname.function.

 

if you make a static method and tried that, it would say you couldn't. 

 

 

So basically static means everything is already there. You are not creating a new instance of that object,

Edited by Satire

As I can see noone is answering your second question about unchecked warning

Most likely you have an ArrayList<?> list = ...

The warning comes from you not using generics in <?>.

To fix it you just need to specify the type of the list by doing <String> or <Integer> or whatever you want to use.

This answer might not apply to what you are doing because you didnt provide any code to us to look at where the warning happens.

Edited by Vilius

I have a few questions about Java.

 

  1.  When should I declare a method as "static"? I tried looking it up but I don't quite understand
  2.  What does it mean when Intellij tells me I am making an "unchecked call"?
  3.  At what point does it make more sense to create a separate class rather than use enum's

If you need to see my script to make sense of any of the above questions, let me know and I'll post it

 

Thanks for your help!

 

1. Generally you should try and avoid the use of static unless you are absolutely sure it is correct to use it, and makes sense to use it. A static method belongs to the class and not any instance of the class. It is commonly used for utility methods, another example of it's use would be in the Singleton Pattern. You will find a lot of amateur programmers abusing the static keyword due to their lack of understanding of OOP.

 

2. You are probably getting this warning because you are using raw types, read a tutorial on Java generics

 

3. An Enum is a class, it can still have methods etc. It is generally used when you want to specify a fixed list of constants. For example you may have a Tree Enum that specifies a fixed list of Trees someone can choose from in your script.

 

TL;DR Follow some more tutorials and learn some more Java

  • Author

As I can see noone is answering your second question about unchecked warning

Most likely you have an ArrayList<?> list = ...

The warning comes from you not using generics in <?>.

To fix it you just need to specify the type of the list by doing <String> or <Integer> or whatever you want to use.

This answer might not apply to what you are doing because you didnt provide any code to us to look at where the warning happens.

 

Here is the code

comboBox.setModel(new DefaultComboBoxModel<>(script.getTrees()));

getting the warning right over the comboBox.setModel part

Here is the code

comboBox.setModel(new DefaultComboBoxModel<>(script.getTrees()));

getting the warning right over the comboBox.setModel part

 

You probably declared your JComboBox like:

JComboBox comboBox = new JComboBox();

When it should be:

JComboBox<Type> comboBox = new JComboBox<>();

Where "Type" is whatever type script.getTrees() returns

 

Edited by Explv

  • Author

You probably declared your JComboBox like:

JComboBox comboBox = new JComboBox();

When it should be:

JComboBox<Type> comboBox = new JComboBox<>();

Where "Type" is whatever type script.getTrees() returns

 Ahhhh that makes sense, thanks!

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.