Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the dot-notation between class names and what does it mean?

What is the meaning of this .notation (AlertDialog.Builder) in a class constructor?

public Dialog onCreateDialog(Bundle savedInstanceState) {

    return new AlertDialog.Builder(getActivity())
        .setTitle(R.string.date_picker_title)
        .setPositiveButton(android.R.string.ok, null)
        .create();

}

Does it mean that the Builder class is defined inside the AlertDialog class? Or Builder is a method, but its first letter is capitalized so I'm confused.

like image 372
Jezer Crespo Avatar asked Sep 26 '13 14:09

Jezer Crespo


2 Answers

This pattern is called method chaining.

Builder is a static inner class of AlertDialog.

Each method in Builder returns a Builder (usually "this") instead of void.

like image 146
dkatzel Avatar answered Sep 19 '22 07:09

dkatzel


This means that Builder is a static nested class in AlertDialog class, that is

class AlertDialog {

   static class Builder {
..
like image 30
Evgeniy Dorofeev Avatar answered Sep 19 '22 07:09

Evgeniy Dorofeev