Is there a way to recognise a Java 16 record's canonical constructor via reflection?

15

Assuming I have a record like this (or any other record):

record X(int i, int j) {
    X(int i) {
        this(i, 0);
    }
    X() {
        this(0, 0);
    }
    X(String i, String j) {
        this(Integer.parseInt(i), Integer.parseInt(j));
    }
}

Is there a way to find this record's canonical constructor via reflection, i.e. the one that is implicitly declared in the RecordHeader?

Share
Improve this question
3
  • 5
    It's called a canonical constructor – ZhekaKozlov Apr 16 at 14:13
  • Working on support for records in jOOQ, eh? :) – Lii Apr 26 at 11:36
  • 1
    @Lii: Yes :) It's already done and ready for jOOQ 3.15 due in Q2 2021: github.com/jOOQ/jOOQ/issues/11778. jOOQ always supported records, but only when passing arguments by index, not by name. Passing by name will now be possible as well, without having to resort to @ConstructorProperties or javac -parameters – Lukas Eder 2 days ago

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue