Hi I've got a very simple class defined like this
public class Pokus {
public static String loginToken;
public String neco = "neco";
public Pokus() {
}
public static String getLoginToken() {
return loginToken;
}
public static void setLoginToken(String loginToken) {
Pokus.loginToken = loginToken;
}
}
When I create an instance of this class
Pokus pokus = new Pokus();
pokus.setLoginToken("bla1212");
In a debugger I can see that object pokus has a field/variable called "neco" but not that static variable "loginToken".
debbuger in Android Studio
Is there any way to see static variables as well as the non-static ones?
Variables. We can see the values of variables during the execution under the Variables view. In order to see the static variables, we can select the drop-down option Java -> Show Static Variables. Using the variables view, it's possible to change any value to the desired value during the execution.
C++ Programming Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. There would only be one copy of each class variable per class, regardless of how many objects are created from it.
Thanks guys I knew all of this but didn't know that debugger is taking this into consideration. There is an option to show static field Settings > Build,Execution, Deployement > Debugger > Data Views > Java
Debugger shows it properly, pokus
is instance of class Pokus
so it have standard method and properties from class Pokus
, static methods and properties are in Class not in instance of Class. Static properties are shared for every object created from class Pokus
( or for every component in program if their are public ) so debugger properly not shows them as properties of single instance.
To show static variable examine class not instance. When debugger stops on breakpoint You can use console and write Pokus.someStaticVar
and You will see current value. Console is available in debugger - http://imgur.com/a/nHfEo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With