Generics and Wildcards in Java | Part 1 | Generics with Wildcards in Java Made Simple | Geekific

Поділитися
Вставка
  • Опубліковано 7 лип 2024
  • Support us on Patreon: / geekific
    GitHub Repository: github.com/geekific-official/...
    Stay updated on our videos by subscribing to the channel and hitting the like button!
    In this video we cover Java Generics and Wildcards. Additionally, we answer why and when you should make use of them while developing an application or writing any piece of code.
    Timestamps:
    00:00 Introduction
    00:25 What are Generics?
    02:29 Implementing Generics in Java
    03:38 What are Wildcards?
    05:07 Bounded Generics and Wildcards
    07:27 Why can't primitive types be used with Generics?
    08:08 Recap
    08:27 Thanks for Watching!
    If you found this video helpful, check other Geekific uploads:
    - Must Know Java Keywords!: • Must Know Java Keyword...
    - Association, Aggregation and Composition Explained: • UML Class and Object D...
    - Generics and Wildcards in Java Made Simple: • Generics and Wildcards...
    - LinkedList Implementation in Java: • Implementing the Linke...
    - Functional Interfaces and Lambda Expressions in Java: • Functional Interfaces ...
    - Java Streams Explained with Examples: • Java Stream API Explai...
    - Object-Oriented Programming Fundamentals: • What is Object-Oriente...
    #Geekific #Generics #Wildcards #Java

КОМЕНТАРІ • 35

  • @ZenjobBuddyJensJeremies
    @ZenjobBuddyJensJeremies Рік тому +4

    Thank you so much for this. The first good explanation of wildcards I have seen so far!

  • @bluem03
    @bluem03 Рік тому +2

    Why shouldnt i always use Wilcards? and just bound to a specific Type

  • @pavolalmasi3760
    @pavolalmasi3760 2 роки тому +3

    I am so happy that I've found your channel, your videos are super informative and everything is very well explained, keep it up

    • @geekific
      @geekific  2 роки тому +1

      Thank you! Glad I could help :)

  • @kalebnegussie8140
    @kalebnegussie8140 2 роки тому +2

    Well done. I had a question and you answered it 100%. Awesome video. Thanks.

    • @geekific
      @geekific  2 роки тому +1

      Glad I did! Happy to help :)

  • @manux7739
    @manux7739 4 місяці тому

    thanks for the explanation!

  • @ucanhtran4372
    @ucanhtran4372 7 місяців тому

    GREAT EXPLANATION !!!!

  • @markconnolly5260
    @markconnolly5260 Рік тому

    Great videos. Live them ❤

  • @DivinityAgarioMore
    @DivinityAgarioMore 3 роки тому +15

    You are very good at explaining. For the future, maybe you can look at providing realtime problems and solutions to deepen our understanding further. Other than that, excellent video!

    • @geekific
      @geekific  3 роки тому +3

      Thanks a lot, happy you liked it! And great suggestion will keep it in mind for the future :)

  • @alvaro1379
    @alvaro1379 8 місяців тому

    wow this was so well explained thanks for the video!!

  • @coop6734
    @coop6734 Рік тому +1

    Thank you!

  • @innerpeace5877
    @innerpeace5877 9 місяців тому

    you are the best your video saved me ily

  • @Ihavetoreturnsomevideotapes
    @Ihavetoreturnsomevideotapes 2 роки тому +2

    You are so good , finally I understood wildcards

  • @pedromedeiros8025
    @pedromedeiros8025 3 роки тому +1

    It was very helpful. Great job!

    • @geekific
      @geekific  3 роки тому +1

      Glad! Thank you!

  • @notsoholyspirit9312
    @notsoholyspirit9312 2 роки тому +1

    Extremely helpful video !!

    • @geekific
      @geekific  2 роки тому +1

      Glad you think so!

  • @louzexuzhou
    @louzexuzhou 3 роки тому +1

    This is gold.

    • @geekific
      @geekific  3 роки тому +1

      Thanks a lot! Your words are gold to me :)

  • @esoterikouno
    @esoterikouno 2 роки тому +1

    thx, now I understand.

    • @geekific
      @geekific  2 роки тому

      Glad I could help! :)

  • @ionguzun3952
    @ionguzun3952 Рік тому

    nice video

  • @bjugdbjk
    @bjugdbjk 2 роки тому +1

    Great and Simple to the point !! One question though, u mean Generics are class wise and wildcards are for Method wise boundaries ? is there any other difference further ..

    • @geekific
      @geekific  2 роки тому +2

      Generics can actually be used for methods as well as for classes, when we do so the method is called a generic method, so the type parameter will be tied to the method alone and not the class. However, making use of the wildcard at class level won't really make sense, your code won't compile. Wildcards are used in Java to handle variance, and you can't create a class if you don't know what attributes it defines! We will be covering all these in a part 2 Generics video, stay tuned!
      Hope this answers your question :) Cheers!

  • @kakashi99908
    @kakashi99908 2 роки тому +1

    Hello I am remaking data structures to better understand how to use them. Can you explain wild cards used in the class level like this: public class MaxPriorityQueue

    • @geekific
      @geekific  2 роки тому +2

      Hello, we will be uploading a video Part 2 that dives in the details of generics and should answer all of your questions regarding this topic! Stay Tuned!

  • @lucasf.v.n.4197
    @lucasf.v.n.4197 2 роки тому

    No ? super T explanation thumbs down

    • @geekific
      @geekific  2 роки тому

      Thanks for the review! However, am not sure what seems to be the problem or which parts of the video weren't clear, can you elaborate so we can fix it?

    • @lucasf.v.n.4197
      @lucasf.v.n.4197 2 роки тому

      @@geekific u only explained

    • @geekific
      @geekific  2 роки тому +1

      You are right :) We'll be working on a part 2 generics video to expand further on the subject! Stay Tuned!
      And meanwhile, as a quick answer to your question: 'extends' means that the generic type (?) has to be a subclass of T, however, 'super' means that the generics type has to be a super class of T, in other terms it is T that extends the generic type (T represents the lower bound here). Hope this helps. Cheers!

    • @lucasf.v.n.4197
      @lucasf.v.n.4197 2 роки тому

      @@geekific Got it; but when should I be using which? And why in the documentation there are methods that use super? For example, the Stream interface has the method forEach, that takes a "Consumer

    • @geekific
      @geekific  2 роки тому +1

      Okay, the fully detailed answer will have to wait for the video, but in short remember PECS (Producer extends, Consumer super). When you are producing or "reading" use extends, when you are consuming or "writing" go for super and if you need both do not use a wildcard just T. They make your code more flexible by allowing the use of subtypes and supertypes when needed. Stay tunned for more details in an upcoming video!