What is CrimeFragment.this?


#1

In CrimeFragment.java, the Fragment argument to setTargetFragment is CrimeFragment.this. I thought I knew Java, but I’m baffled by this, how does “this” get set, and is it maybe a global static variable?


#2

this is a java keyword that gives you the instance of the current class. So, when you call setTargetFragment, you are passing in the current fragment as one of the parameters. this is a language feature and it’s set up automatically.

https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html