What does the 'this' operator do in Java? I still don't get it.
Refers to any generic object. Think of it as the "x" in algebra
>>16791656
Do you know object oriented programming?
Obviously you don't.
You might want to check in to it.
Basically you create a class with something like this
Class Faggot(){
private string name;
private int age;
private boolean cuck;
public void setName(string name){
this.name = name;
}
}
that would go in a Faggot.java file, now this "class" thing is like a blueprint for an object, and object basically is 'instance' of a class, a group of variable and functions that you use to be more organized, reduce complexity at some point and most importantly reusability.
Say that you want to create an object based on the class described before, you should use something like the following:
Faggot myObj = new Faggot();
now we have created the object myObj, basically object means a "reserved space on memory tho hold structured data". So now the myObj object has the properties that the "blueprint" Faggot represents. So embedded on it you can find the properties "name", "age","cuck".
Now as you can see I also defined the function "setName" that receives a string named "name" and assigns its value to the object property "name". When the operator "this" is used, it refers to the object that is calling the property, in this case myObj. To use this method we could use the following 'myObj.setName("OP")', that would give the property name of the object the value of "OP". Before the method was called the property "name" was null.
>>16791720
yeah, I don't know anything about it, hence why I asked this question
>>16791720
thx tho!
>>16791730
Just look for a tutorial in youtube.
when it comes to programming you'll fine 60% of what you could need there.
This should go on /g/ desu, but:
If you have a class defined as such:
class A{
String s="bye";
void q(){
String s = "hi";
System.out.println(s);
System.out.println(this.s);
}
}
It will print:
hi
bye
Why? Because 's' in q() is local to q(), and Java chooses the most local variables to use as 's'. However, when you call 'this.s', it refers specifically to the class variables. You can safely leave it out 99% of the time, but it can make things more explicit, and sometimes makes debugging easier if someone has really shitty naming conventions (as in the example I just gave).
>>16791656
It refers to the class instance of something.