Thursday 28 July 2022

How to check whether a type is record or not?

'java.lang.Class' provides 'isRecord' method which returns true if and only if this class is a record class, otherwise false.

 

Signature

public boolean isRecord()

 


 

 

Point.java

package com.sample.app.reflections;

public record Point(int x, int y) {

}

 

RecordTypeCheck.java

package com.sample.app.reflections;

public class RecordTypeCheck {

    public static void main(String[] args) {
        boolean isRecord = Point.class.isRecord();

        System.out.println("Is Point record type? " + isRecord);
    }

}

 

Output

Is Point record type? true

 

References

https://openjdk.org/jeps/384

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment