RFR 9: 8138963 : java.lang.Objects new method to default to non-null (original) (raw)
Ivan Gerasimov ivan.gerasimov at oracle.com
Tue Oct 6 13:53:47 UTC 2015
- Previous message: RFR 9: 8138963 : java.lang.Objects new method to default to non-null
- Next message: RFR 9: 8138963 : java.lang.Objects new method to default to non-null
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Roger!
I didn't notice the message, so first commented in the Jira.
Would it make sense to also add a variant with the second argument of type Supplier, so that it can be lazily calculated only if needed? Something like: public static T nonNull(T obj, Supplier nullDefaultSupplier) { return (obj != null) ? obj : nullDefaultSupplier.get(); }
Sincerely yours, Ivan
On 06.10.2015 16:43, Roger Riggs wrote:
Java.lang.Objects contains a number of convenience methods to make it easier to handle references that are null. For example, toString(obj, nullDefault),
A new method is proposed to return the reference or a default value if the reference is null. static T nonNull(T obj, T nullDefault); Alternatives to the method name include nonNullOrElse ( using the java.util.Optional name pattern) or nonNullOrDefault Please review and comment. Webrev: http://cr.openjdk.java.net/~rriggs/webrev-object-non-null/ Issue: https://bugs.openjdk.java.net/browse/JDK-8138963 Thanks, Roger
- Previous message: RFR 9: 8138963 : java.lang.Objects new method to default to non-null
- Next message: RFR 9: 8138963 : java.lang.Objects new method to default to non-null
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]