Jump to content

Private final


Recommended Posts

Posted

Hello people of OSBot,

I have a short question, if I set a variable in the private final part of the script like this:

    private final
    Position sellPoint = new Position (3209, 3216, 2);

And later change this, in this case, change it to position (2222, 2222, 2) for example, in a private boolean statement or private void.

1. Will this be possible because of the private part?

2. Will it be changed back to the original (3209, 3216, 2) at any point?

Hope to hear from you, and if you feel like it please leave a explanation so I can learn more from it.

 

 

Posted (edited)

Ok, I suggest you learn some basic java before you start scripting, shouldn't take you long and it will save you a lot of time.
 

As for your question:

 

private means that specific var or func is only accessible from the class where you declared it.

For example:

If you use:

private int year = 2017;

in your main class, you will NOT be able to access the var year from an other class.

 

As for the final keyword

Final is a keyword that is used to declare a var as a final var, which means you can't change it. (It is constant)

In order to change the sellPoint you will need to not declare it as a final.

For example:

this is OK

 private Position sellPoint = new Position (3209, 3216, 2);

sellPoint = new Position (0, 0, 0);

But this is NOT

 private final Position sellPoint = new Position (3209, 3216, 2);

sellPoint = new Position (0, 0, 0);

 

27 minutes ago, evert123 said:

Hello people of OSBot,

I have a short question, if I set a variable in the private final part of the script like this:

    private final
    Position sellPoint = new Position (3209, 3216, 2);

And later change this, in this case, change it to position (2222, 2222, 2) for example, in a private boolean statement or private void.

1. Will this be possible because of the private part?

2. Will it be changed back to the original (3209, 3216, 2) at any point?

Hope to hear from you, and if you feel like it please leave a explanation so I can learn more from it.

 

 

 

 

EDIT: A good place to start learning Java if you need: (not sure if i can post links, google "The new boston java")

Edited by HunterRS
  • Like 1
Posted
11 hours ago, HunterRS said:

Ok, I suggest you learn some basic java before you start scripting, shouldn't take you long and it will save you a lot of time.
 

As for your question:

 

private means that specific var or func is only accessible from the class where you declared it.

For example:

If you use:

private int year = 2017;

in your main class, you will NOT be able to access the var year from an other class.

 

As for the final keyword

Final is a keyword that is used to declare a var as a final var, which means you can't change it. (It is constant)

In order to change the sellPoint you will need to not declare it as a final.

For example:

this is OK


 private Position sellPoint = new Position (3209, 3216, 2);

sellPoint = new Position (0, 0, 0);

But this is NOT


 private final Position sellPoint = new Position (3209, 3216, 2);

sellPoint = new Position (0, 0, 0);

 

 

 

EDIT: A good place to start learning Java if you need: (not sure if i can post links, google "The new boston java")

Thank you very much for the detailed explanation.
I will definitely start learning more about the basics of Java, but for now I don't have much time and I use this script as a puzzle that I'm aloud to play with whenever I made some real progress with my thesis.

I know this is not really efficient on my side and even less efficient on the communities side, but ill try to make up for it in the future.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...