Check for null object and null value contained in object in Java 8 way

Viewed 7828

how to rewrite this function to be more Java 8 with Optionals? Or should I just leave it as it is?

public void setMemory(ArrayList<Integer> memory) {
    if (memory == null)
        throw new IllegalArgumentException("ERROR: memory object can't be null.");
    if (memory.contains(null))
        throw new IllegalArgumentException("ERROR: memory object can't contain null value.");

    this.memory = memory;
}
9 Answers
Related