+ 1

Why are we creating the object this way?

Say my code is this:- Intent myIntent = Intent.createChooser(intent, "Send message..."); Is myIntent an object? Why is it written "Intent.createChooser(intent, "Send message...");" I mean i know what it does but, why is it written this way? This ain't the normal way of creating objects right?

10th Dec 2020, 6:03 AM
Mons Joseph
Mons Joseph - avatar
3 Antworten
+ 2
Mons Joseph Yes here myIntent is an object which is returned by your static method createChooser. If you call method with class name that method would be static.
10th Dec 2020, 6:29 AM
A͢J
A͢J - avatar
+ 3
Mons Joseph You should read about "static" keyword 👇 https://www.sololearn.com/learn/Java/2159/
10th Dec 2020, 6:43 AM
Minho
Minho - avatar
+ 1
It's somewhat of a design pattern. If you look it up you. Design patterns help to write robust and reusable code. In this case it could be a creational pattern that creates an instance of class.
10th Dec 2020, 7:45 AM
Akib
Akib - avatar