thank you , as you said , it is a bit confusing , i would like that you made another video on the same subject because generics in and out are really difficult to understand to me, hope you will be able to...
Wonderful explanation But I don’t see any use case where these are going to get used. Can you also provide a simple use case? You can even provide it in reply to this comment if you think it’s feasible. Furthermore, in your consumer example, in main function, you created object of ConsumerPhone(). I don’t understand what purpose this served at the end. Can you please elaborate on that too? Thank you very much, you’ve got yourself a subscriber The exact 700th subscriber 😄
Thank you so much Asad for subscribing. In out types are basically useful when we want to restrict the usage of our functions. For example like in Java we have generic functions say interface Source { static final T next(); } Now in this case the next function which is called is a producer function. But it can only return object of subclass of Object. In this case we can store something like Object o = Source.next() Now this is ok if we are only passing objects of same data type everytime and reading them but not writing in them. However if we create a write function also static final write(T obj) Now in this case write function can take any argument which is extending Object class. Now this can cause issues because lets say the producer function returned us type String and we called write function and try to write in object something other than String then it will give us error. To prevent this Kotlin introduced in out types so that compiler knows which class can have producer functions that return only certain type of values and which Consumer classes can have write functions on which write methods can only be called. For more understanding this link is also helpful kotlinlang.org/docs/generics.html#type-projections Hope it helps
Very nice explanation :)
Thank you so much
AWESOME EXPERIENCE
Thank you so much
thank you , as you said , it is a bit confusing , i would like that you made another video on the same subject because generics in and out are really difficult to understand to me, hope you will be able to...
Hey Juan, thank u so much for your kind words. Yes will try to make more example videos in future
Jalde buna main be purhaon ga!
Woow this is a good article
Thank u so much Deepak
Great Explanation!
Thank u so much Poncho
mam can u please make a playlist of
google kotlin course which in documentation
@@mohammedharoon1167 Google Kotlin fundamentals playlist th-cam.com/video/IfW0b1a1TrA/w-d-xo.html
Wonderful explanation
But I don’t see any use case where these are going to get used. Can you also provide a simple use case? You can even provide it in reply to this comment if you think it’s feasible.
Furthermore, in your consumer example, in main function, you created object of ConsumerPhone(). I don’t understand what purpose this served at the end. Can you please elaborate on that too?
Thank you very much, you’ve got yourself a subscriber
The exact 700th subscriber 😄
Thank you so much Asad for subscribing. In out types are basically useful when we want to restrict the usage of our functions. For example like in Java we have generic functions say
interface Source {
static final T next();
}
Now in this case the next function which is called is a producer function. But it can only return object of subclass of Object. In this case we can store something like
Object o = Source.next()
Now this is ok if we are only passing objects of same data type everytime and reading them but not writing in them.
However if we create a write function also
static final write(T obj)
Now in this case write function can take any argument which is extending Object class. Now this can cause issues because lets say the producer function returned us type String and we called write function and try to write in object something other than String then it will give us error.
To prevent this Kotlin introduced in out types so that compiler knows which class can have producer functions that return only certain type of values and which Consumer classes can have write functions on which write methods can only be called.
For more understanding this link is also helpful
kotlinlang.org/docs/generics.html#type-projections
Hope it helps