Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

ComponentName extension function for Context #526

Open
davethomas11 opened this issue May 2, 2018 · 3 comments
Open

ComponentName extension function for Context #526

davethomas11 opened this issue May 2, 2018 · 3 comments

Comments

@davethomas11
Copy link
Contributor

What do you think about a simple extension for creating ComponentName instances using a Context?

inline fun <reified T> Context.componentName() = ComponentName(this, T::class.java)
@JakeWharton
Copy link
Contributor

Should there be an overload which takes a string as well?

@davethomas11
Copy link
Contributor Author

davethomas11 commented May 24, 2018

Sure, I don't see why not... hmm. Would there be a case where you have a Component you don't have the class reference for? Yes, actually if the Component is in another application. Though in that case, you would not be using a Context from your application to create it.

There must be a use case why that constructor exists. I'm not sure when ComponentName(context, string) is generally used, or if it is merely a convenience method. It does result in one less function call since it does not need to call getName() on the class to get the String value.

Shrug I'd lean towards not including the string constructor unless I am missing a general use case where this would be useful.

@HeyAlex
Copy link

HeyAlex commented Jul 9, 2018

Find this really usefull. PR #594

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants