Can anyone explain concept of in and out. In kotlin generic. Example code will help much better. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Can anyone explain concept of in and out. In kotlin generic. Example code will help much better.

2nd Oct 2019, 7:43 PM
Smit Kalkani
Smit Kalkani - avatar
3 Respostas
+ 5
It is definitely a confusing concept. I have used it, but am by no means an expert. This link was how I managed to get it working. Given my hundreds of Kotlin codes, I haven't found where as yet. https://blog.kotlin-academy.com/kotlin-generics-variance-modifiers-36b82c7caa39
6th Oct 2019, 4:11 AM
John Wells
John Wells - avatar
+ 3
The out seems similar to wildcard in Java, but I've never made generics in Java so have never played with them. However, placing constraints on the types matches too and has similar syntax: <T : Number> would allow Int or Double types.
6th Oct 2019, 1:04 PM
John Wells
John Wells - avatar
+ 2
Sir one more thing this in and out has any similarities with concept of wildcard extends and super upper bounded and lower bounded wild cards? In java.
6th Oct 2019, 10:12 AM
Smit Kalkani
Smit Kalkani - avatar