Using “this” with class name

Usually, you can use only this. But, sometimes this makes reference to an inner class… so, for example: Button button = (Button)findViewById(R.id.ticket_details_sell_ticket); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // it will be wrong to use only “this”, because it would // reference the just created OnClickListener object Intent login = new Intent(ClassName.this, … Read more

When should I make explicit use of the `this` pointer?

Usually, you do not have to, this-> is implied. Sometimes, there is a name ambiguity, where it can be used to disambiguate class members and local variables. However, here is a completely different case where this-> is explicitly required. Consider the following code: template<class T> struct A { T i; }; template<class T> struct B … Read more

What does the variable $this mean in PHP?

It’s a reference to the current object, it’s most commonly used in object oriented code. Reference: http://www.php.net/manual/en/language.oop5.basic.php Primer: http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html Example: <?php class Person { public $name; function __construct( $name ) { $this->name = $name; } }; $jack = new Person(‘Jack’); echo $jack->name; This stores the ‘Jack’ string as a property of the object created.

Java: Class.this

LocalScreen.this refers to this of the enclosing class. This example should explain it: public class LocalScreen { public void method() { new Runnable() { public void run() { // Prints “An anonymous Runnable” System.out.println(this.toString()); // Prints “A LocalScreen object” System.out.println(LocalScreen.this.toString()); // Won’t compile! ‘this’ is a Runnable! onMake(this); // Compiles! Refers to enclosing object onMake(LocalScreen.this); … Read more

std::shared_ptr of this

There is std::enable_shared_from_this just for this purpose. You inherit from it and you can call .shared_from_this() from inside the class. Also, you are creating circular dependencies here that can lead to resource leaks. That can be resolved with the use of std::weak_ptr. So your code might look like this (assuming children rely on existence of … Read more

difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this

Toast and Intent, both requires reference to context. And getApplication, getApplicationContext, LoginActivity.this and getBaseContext, they all offer reference to the context. Now the thing confuses is the declaration of different contexts and their specific-usage. To make things simple, you should count two types of context available in the Android framework. Application Context Activity Context Application … Read more

When should I use “this” in a class?

The this keyword is primarily used in three situations. The first and most common is in setter methods to disambiguate variable references. The second is when there is a need to pass the current class instance as an argument to a method of another object. The third is as a way to call alternate constructors … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)