Reputation: 2293
I'm a Java noob. When writing code that uses static or instance methods that return references to Objects, is it safe to assume that they will be run from left to right?
http://developer.android.com/reference/android/os/Environment.html (see getExternalSto... returns File) http://developer.android.com/reference/java/io/File.html (see getAbsolutePath() returns String)
i.e.
String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
or should you do this as a safeguard?
String storagePath = ( Environment.getExternalStorageDirectory() ).getAbsolutePath();
Upvotes: 0
Views: 90
Reputation: 32807
The .
operator has left associativity i.e operands are grouped from left
So,yes it is safe to assume that they will be grouped from left to right
But what is associativity?
When operators have same precedence,associativity governs the order in which the operations are performed..i.e from left
(operands are grouped from left) or right
(operands are grouped from right) or none
Upvotes: 1
Reputation: 525
Of course, no brackets neccessary. getExternalStorageDirectory() returns an object, and then you call the method getAbsolutpath() of this object.
Upvotes: 2