Hi, how can i make an universal comporator in kotl...
# announcements
z
Hi, how can i make an universal comporator in kotlin?
Copy code
fun<T : Comparable<T>, K> comparePairByFirst() : Comparator<Pair<T, K>>  = Comparator { p1, p2 -> p1.first.compareTo(p2.first) }
I have this code and it works, but creates a new similar comparator every use. I think it is bad. How can I make it better? ------------------------------------------------------------------------------------------------------------------------------------------------------------ How i can "this" method in inline functions? I want to get that class to log it.
e
Is it possible to write universal comparator for all cases?
Can you share number of your real cases and maybe it is possible to write something generic for your subset of all cases
z
I need to use it in generic classes
Tha answers: 1. inline it 2. fun<refiend T> foo() { t::class... }