[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

What does the 'this' operator do in Java? I still

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 8
Thread images: 2

File: hqdefault (1).jpg (12KB, 480x360px) Image search: [Google]
hqdefault (1).jpg
12KB, 480x360px
What does the 'this' operator do in Java? I still don't get it.
>>
File: RuntUEC.jpg (348KB, 1228x1478px) Image search: [Google]
RuntUEC.jpg
348KB, 1228x1478px
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.
Thread posts: 8
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.