5

I know if I run a program, it will likely express one way or another: what it is expecting from each variable. But I would like to determine on my own when I read over each page of Android code etc. e.g:

  • How could I determine what size or length an android program is expecting a string array to be?
  • Whether an integer or double, is expected to be positive or negative?

etc.

Help in this regard would be much appreciated.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
LoneArcher
  • 57
  • 3
  • 2
    Erm... your own source comments and documentation? This isn't specific to Android either, it's just Java code. – Matt Taylor Jun 05 '15 at 13:42
  • You are referring to preconditions/postconditions and invariants. There are some annotations you can use and there are other libraries you can use to either document or enforce these. See http://stackoverflow.com/questions/6816298/is-there-an-beautiful-way-to-assert-pre-conditions-in-java-methods – David Wasser Jun 05 '15 at 15:14

1 Answers1

0

You can set breakpoints in your code and examine all of the variables when the program pauses. This would give you a general idea of whether the integers were positive or negative, the length and content of the strings, etc. It could be useful if the code was poorly documented.

Assuming you are using Android Studio you can follow this guide:

https://developer.android.com/tools/debugging/debugging-studio.html

bleezy
  • 26
  • 7
  • As above I was wanting to identify, how to figure out the characteristics a program is expecting from a variable **prior to run-time** e.g. when I am simply reading over a page of Android code. In which case the above **although informative**, *isn't helpful* – LoneArcher Jun 05 '15 at 22:48