Pattern Matching in Java: 5 Examples for Busy Developers

Поделиться
HTML-код
  • Опубликовано: 17 дек 2024

Комментарии •

  • @mustafailikkan7068
    @mustafailikkan7068 Год назад +9

    Thanks Mala, I like your teaching style.

  • @dirkweissenbacher3677
    @dirkweissenbacher3677 Год назад +4

    Great Video! Easy to understand. Thank you very much.

  • @BrazenNL
    @BrazenNL Год назад +4

    10:13 If you place the camera view a little higher we can see the whole shortcut line.

    • @JavaWithMala
      @JavaWithMala Год назад +4

      I apologize for the overlook. I've noted it and won't repeat this mistake. Thanks for your feedback.

    • @BrazenNL
      @BrazenNL Год назад +2

      @@JavaWithMala Thank you for the videos.

  • @lucasguaru
    @lucasguaru Год назад +3

    Nice vídeo. Very helpful. If I can make a suggestion, please take sometime on The option selected before hit enter. It would let me check the option

  • @bouihabdelouahed1579
    @bouihabdelouahed1579 Год назад

    Very helpful video indeed. Thank you.

  • @perwramdemark3063
    @perwramdemark3063 Год назад +2

    Great stuff I learnt a lot in short time 🎉😊

  • @Quillraven
    @Quillraven Год назад +3

    Which theme are you using in this video? It is nice to look at for a video imo.

    • @JavaWithMala
      @JavaWithMala Год назад +2

      Darcula by JetBrains :-)

    • @Quillraven
      @Quillraven Год назад +2

      @@JavaWithMala ah really? For some reason it looks completely different on my machine 😅

    • @JavaWithMala
      @JavaWithMala Год назад +3

      @@Quillraven I'm also using the new UI in IntelliJ IDEA. I'm unsure if that explains the difference 🙂

    • @tiagozc1
      @tiagozc1 Год назад +1

      @@JavaWithMala I get it that the overall theme is Darcula with the new UI, but what about the editor Color scheme? For sure it isn't Darcula with all those blue and grey tones 😅

  • @Channel-iu6de
    @Channel-iu6de Год назад +3

    great vid. thanks.

  • @CryptoCodeZone
    @CryptoCodeZone Год назад

    Great Video, even for Kotlin user,
    or Just "switch" to Kotlin!😀😀😀

  • @nasamind
    @nasamind Год назад +1

    If Else, how many time have you written one? 😀 Always

  • @ChrisAthanas
    @ChrisAthanas Год назад

    Very useful

  • @praveen7730
    @praveen7730 Год назад +2

    Title is confusing, i thought you will discuss about pattern matching or regular expressions in java😂😂

  • @mondoshigua
    @mondoshigua Год назад

    👋🏼🇨🇴🧔🏻👍🏼🤝🏻 Saludos desde Colombia.

  • @cya3mdirl158
    @cya3mdirl158 Год назад

    Java is like baroque full of splendor i Preffer kotlin

    • @RustedCroaker
      @RustedCroaker Год назад +1

      Java is like a good written book - easy to fallow the story line and every paragraph is perfectly understandable. Unlike in Kotlin, with its unnecessary fight against the fake "code bloat" concept.
      If you hate "code bloat" learn Perl. Your code wouldn't be shorter then that. But most the time it would be easer to write a new code from scratch then understand what the old one is doing.

    • @adambickford8720
      @adambickford8720 Год назад

      @@RustedCroaker Living up to the name!

  • @pavolvarga4724
    @pavolvarga4724 Год назад +1

    Guys, sorry, I see that you are trying to do a good job,
    mostly going over and beyond, but iterating over an Enumeration,
    or switch/case, that is not right, guys you are trying to teach
    will repeat antipatterns like these. :-(
    So to make it right:
    @AllArgsConstructor
    enum SingleUsePlastic {
    BOTTLE("Booth 4: Pick up a glass bottle"),
    SPOON("Pantry: Pick up a steel spoon"),
    CARRY_BAG("Booth 5: Pick up a cloth bag"),
    ;
    final String replacement;
    }
    String getReplacements(SingleUsePlastic plastic) {
    return plastic.replacement;
    }
    So the method above will be quite a duplicity itself.
    And if needed any sort of semantics, enumerations
    can always implement interfaces, the OOP approach could be like this:
    public class Sample {
    interface Arithmetic {
    int apply(int num1, int num2);
    }
    enum Operator implements Arithmetic {
    PLUS('+') {
    @Override
    public int apply(int n1, int n2) {
    return n1 + n2;
    }
    },
    MINUS('-') {
    @Override
    public int apply(int n1, int n2) {
    return n1 - n2;
    }
    },
    CROSS('*') {
    @Override
    public int apply(int n1, int n2) {
    return n1 * n2;
    }
    },
    DIVIDE('/') {
    @Override
    public int apply(int n1, int n2) {
    return n1 / n2;
    }
    },
    ;
    final char operator;
    Operator(char operator) {
    this.operator = operator;
    }
    }
    Operator getOperator(char c) {
    switch (c) {
    case '+':
    return PLUS;
    case '-':
    return MINUS;
    case '*':
    return CROSS;
    default:
    return DIVIDE;
    }
    }
    }