Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can maybe get there in kotlin with a generic type with multiple constraints in a where clause. Let’s say you have Sorted and NonEmpty as interfaces (could be empty marker interfaces so they behave like tags). Then you can write a method

  fun <T> doSomething(values: T) where T: Sorted, T: NonEmpty {}
And that function will take any type that has both Sorted and NonEmpty interfaces.


You don't need Kotlin to do this, even Java can do it:

    <T extends Sorted & NonEmpty> void doSomething(T values)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: