Java 22 Previews Statements Before `super(...)` and `this(...)` - Inside Java Newscast #62

Поділитися
Вставка
  • Опубліковано 8 чер 2024
  • Whether for validation, preparation, or splitting and sharing arguments, it can be quite annoying that Java doesn't allow statements before the `super(...)` or `this(...)` call in a constructor. Luckily Java 22 is about to change that with JEP 447, which previews statements before the explicit constructor invocation.
    JEP 447: openjdk.org/jeps/447
    JDK 22: jdk.java.net/22/
    ~~~ Chapters ~~~
    0:00 Intro
    1:40 Constructor Chaining
    2:57 No Statements Before Constructor Invocation
    5:04 JEP 447
    6:40 Prologue Benefits
    7:46 COWS!
    Tags: #Java #OpenJDK
  • Наука та технологія

КОМЕНТАРІ • 28

  • @KangoV
    @KangoV 4 місяці тому +22

    I have hit this a few time and it can be annoying. This is a welcome change.

  • @thoriig3887
    @thoriig3887 4 місяці тому +5

    Oh a cyberpunk Fan and Fan of keep it simple concept. Like it ❤

  • @igorm.9845
    @igorm.9845 3 місяці тому +2

    Cool! About prologue you say: "static context plus a bit more". Can you please tell me what that "a bit more" is?

  • @desoroxxx
    @desoroxxx 4 місяці тому +5

    To answer the question at the start, me, very often even

  • @user-jw9iw2zy1k
    @user-jw9iw2zy1k 4 місяці тому +3

    Can we get a concrete newscast with several practical examples about how to use the new Classfile API, which is totally amazing. I really would like to try them out in my project, but there are so few information about how to use them, please!

  • @DeznekCZ
    @DeznekCZ 4 місяці тому +4

    I'm not the only one, who needs it 🙂
    I do not know, if I use it for this() because it may be rearranged when it's complicated.
    But for super() it's totally game changing.
    No longer we will need (mostly) static constructor methods.

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

      And no longer would we need auxiliary static methods

  • @adilhassan9443
    @adilhassan9443 4 місяці тому +3

    That No LTS always bring smile on my face man! good job though

  • @bawahs
    @bawahs 3 місяці тому

    Very handy and a welcome change.

  • @RobRoss
    @RobRoss 4 місяці тому +2

    In the past I might have created a factory method to handle parameter manipulation before invoking constructors to avoid this issue. This new functionality might obviate that need. However, the modern zeitgeist is a trend towards factory methods/builders and away from constructors, so this new functionality may be a little late. 🤷‍♂️

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

    Interesting approach that improves readability.

  • @RobRoss
    @RobRoss 4 місяці тому +1

    Perhaps those cows are migratory and have flown South for the Winter? 🧐

  • @ekadet7882
    @ekadet7882 2 місяці тому

    static factories?

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

    Gardaş eskiden super anahtar sözcüğünün üstünde kod yazılamıuor muydu?

  • @nazardub9044
    @nazardub9044 2 місяці тому

    Nice cows)

  • @sidneymonteiro3670
    @sidneymonteiro3670 4 місяці тому +1

    More feet will be shot because of this feature than toes saved by it.

  • @rickhunter8216
    @rickhunter8216 4 місяці тому +2

    I'M ON JAVA 8 :-)

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

    Sen Türk müsün bıyıklı Java günleri İstanbul yazıyor t-shirt'ünde.

    • @muaz-memis
      @muaz-memis 11 днів тому +1

      Buna kimse laf etmiş mi diye bakmıştım :)

  • @JorgetePanete
    @JorgetePanete 4 місяці тому +2

    moo();

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

    I am not convinced this is a good change or will make anything easier. I worry this may lead to increased code complexity in overly aggressive inheritance models.

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

    that was a looooooong talk, no code lol

    • @lesserlight
      @lesserlight 4 місяці тому +1

      No code? There is a lot of code in this video.

  • @9-and-3
    @9-and-3 4 місяці тому

    Typically Java…the medicine is worse than the disease

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

    This is great! I once wanted to delegate to a constructor which takes in a JavaFX Button, but if I wanted to set add an image on that Button beforehand, I had to create an IIFE or a static method if I wanted to do that. e.g.
    this(
    ((Supplier)() -> {
    Button btn = new Button();
    btn.setGraphic(graphic);
    return btn;
    }
    ).get(), func);
    which is cursed

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

    I am still not sure why this is relevant. It's good to hear a high level discussion which makes me think through what was said. It just seems like a complicated explanation about constructors that use more code than normal.

    • @marwenlahmar1513
      @marwenlahmar1513 4 місяці тому +1

      If your were to make a video about this, you'd want to target the general audiance regardless of their expertise on the subjet "constructor invocation", some people may not have heard about it before so you can't just drop the information without context. I don't find it complicated, half of the video is explaing how construtor currently work and why they are implemented the way they are. The other half is explaining the new feature and how it may or may not be useful.
      A long time language user could also read the title and know exatly what this feature is about without watching the video, but like I said earlier, this is not given since the general audiance are not on the same expertise level.
      The compromise is this "format"