PuppetHero is a monthly newsletter that will help you supercharge your web-based workflows. With just a little bit of code & time, you can automate repetitive tasks and save time. Sign up, for free, today! The PuppetHero Digest @ PuppetHero.com!

I learn a Kotlin thing everyday.  Today’s thing, “Enforcing-Inheritance-Generic-Thing-in-Kotlin” (I’m terrible with names and terms, there’s an official term for this that I cannot remember). I have a function that starts an activity for a result.  I want to limit this function to only be able to start activities extending an abstract class, FooActivity. In Java:

private void start(Activity activity, Class<? extends FooActivity> cls) {
   // some stuff with intents
}

In Kotlin:

fun start(activity: Activity, cls: Class<out FooActivity>) {
    // some stuff with intents
}

That’s it.  Read more about generics in Kotlin here.

Thanks for reading. ✌🏿