Skip to content

Instantly share code, notes, and snippets.

@StylingAndroid
Last active April 19, 2019 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StylingAndroid/8c718d5d7c449f8b637bfb9b31b17f63 to your computer and use it in GitHub Desktop.
Save StylingAndroid/8c718d5d7c449f8b637bfb9b31b17f63 to your computer and use it in GitHub Desktop.
fun main() {
val classOne = ClassOne()
val color1 = classOne.obtainColor(context, R.color.my_color)
val classTwo = ClassTwo()
classTwo.obtainColor(R.color.my_color, context.resources::getColor)
}
class ClassOne() {
fun obtainColor(context: Context, colorRes: Int) = context.resources.getColor(colorRes)
}
class ClassTwo {
fun obtainColor(colorRes: Int, colorLookup: (Int) -> Int) = colorLookup(colorRes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment