blob: 1c275388bc784c1c9f5d09fc64a3dd5c012efdcf [file] [log] [blame]
Jake Wharton3d656f72019-12-12 23:11:15 -05001// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package backport;
6
7import java.util.NoSuchElementException;
8import java.util.OptionalDouble;
9
10public final class OptionalDoubleBackportJava10Main {
11
12 public static void main(String[] args) {
13 testOrElseThrow();
14 }
15
16 private static void testOrElseThrow() {
17 OptionalDouble present = OptionalDouble.of(2d);
18 assertEquals(2d, present.orElseThrow());
19
20 OptionalDouble absent = OptionalDouble.empty();
21 try {
22 throw new AssertionError(absent.orElseThrow());
23 } catch (NoSuchElementException expected) {
24 }
25 }
26
27 private static void assertEquals(Object expected, Object actual) {
28 if (expected != actual && !expected.equals(actual)) {
29 throw new AssertionError("Expected <" + expected + "> but was <" + actual + ">");
30 }
31 }
32}