blob: 06c85f5f7f31a573da66374bb3b3a2fe838cd383 [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.OptionalInt;
9
10public final class OptionalIntBackportJava10Main {
11
12 public static void main(String[] args) {
13 testOrElseThrow();
14 }
15
16 private static void testOrElseThrow() {
17 OptionalInt present = OptionalInt.of(2);
18 assertEquals(2, present.orElseThrow());
19
20 OptionalInt absent = OptionalInt.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}