Convenience method of choosing the first non-null value starting from the left - Java Object Oriented Design

Java examples for Object Oriented Design:Method Parameter

Description

Convenience method of choosing the first non-null value starting from the left

Demo Code


//package com.java2s;

public class Main {
    /**//from w  ww.j  a  va  2 s .c o  m
     * Convenience method of choosing the first non-null value starting from the left
     * 
     * @param a
     * @param b
     * @return
     */
    @SafeVarargs
    public static <T> T Coalice(T... values) {
        for (T item : values) {
            if (item != null) {
                return item;
            }
        }
        return null;
    }
}

Related Tutorials