Understanding Java Notation

I am trying to use dialogs in Android. In the process, I ran into lines of code as follows:

alertDialogBuilder
            .setMessage("Click yes to exit!")
            .setCancelable(false)
            .setPositiveButton("Yes",new...

This designation is a little strange for me as an old C ++ programmer. This is the same as

alertDialogBuilder.setMessage("Click yes to exit!");
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setPositiveButton("Yes",new...

If so, is this musical part of Java or unique to Android programming? What is the name of this notation (or method)?

+3
source share
3 answers

This idiom is called a method method chain and is not specific to Java or Android. The trick is that methods that otherwise return void return a reference to this, allowing long chains of method calls to the same object.

, . .

+3

++, ( ). , .

Builder!

+1

:

alertDialogBuilder.setMessage("Click yes to exit!").setCancelable(false).setPositiveButton("Yes",new...

, . , , , setMessage(), -, alertDialogBuilder, .

+1

All Articles