0N/A/*
553N/A * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4509267
0N/A * @summary generics: parametric exception type versus overriding
0N/A * @author gafter
0N/A *
288N/A * @compile ParametricException.java
0N/A */
0N/A
0N/Aimport java.io.*;
0N/A
0N/Aabstract class AChurchBoolean {
0N/A public abstract <Return, Parameter, Throws extends Throwable>
0N/A Return accept(IVisitor<Return, Parameter, Throws> visitor, Parameter parameter) throws Throws;
0N/A
0N/A public interface IVisitor<Return, Parameter, Throws extends Throwable> {
0N/A public Return caseTrue(Parameter parameter) throws Throws;
0N/A public Return caseFalse(Parameter parameter) throws Throws;
0N/A }
0N/A}
0N/A
0N/Aclass TrueChurchBoolean extends AChurchBoolean {
0N/A private static TrueChurchBoolean instance = new TrueChurchBoolean();
0N/A private TrueChurchBoolean() {}
0N/A public static TrueChurchBoolean singleton() {
0N/A return instance;
0N/A }
0N/A public <Return, Parameter, Throws extends Throwable>
0N/A Return accept(IVisitor<Return, Parameter, Throws> visitor, Parameter parameter) throws Throws {
0N/A return visitor.caseTrue(parameter);
0N/A }
0N/A}
0N/A
0N/Aclass FalseChurchBoolean extends AChurchBoolean {
0N/A private static FalseChurchBoolean instance = new FalseChurchBoolean();
0N/A private FalseChurchBoolean() {}
0N/A public static FalseChurchBoolean singleton() {
0N/A return instance;
0N/A }
0N/A public <Return, Parameter, Throws extends Throwable>
0N/A Return accept(IVisitor<Return, Parameter, Throws> visitor, Parameter parameter) throws Throws {
0N/A return visitor.caseFalse(parameter);
0N/A }
0N/A}
0N/A
0N/Aclass Pair<T,U> {
0N/A private T first;
0N/A private U second;
0N/A Pair(T first, U second) {
0N/A this.first = first;
0N/A this.second = second;
0N/A }
0N/A T getFirst() {
0N/A return first;
0N/A }
0N/A U getSecond() {
0N/A return second;
0N/A }
0N/A}
0N/A
0N/A// Perhaps a bit of a toy example, but relevant nonetheless.
0N/Aclass ChurchBooleanTest {
0N/A private AChurchBoolean bool;
0N/A public ChurchBooleanTest(AChurchBoolean bool) {
0N/A this.bool = bool;
0N/A }
0N/A public AChurchBoolean readIf(File file, byte[] output) throws IOException {
0N/A return bool.accept(new AChurchBoolean.IVisitor<AChurchBoolean, Pair<File, byte[]>, IOException>() {
0N/A public AChurchBoolean caseTrue(Pair<File, byte[]> parameter) throws IOException {
0N/A FileInputStream input = new FileInputStream(parameter.getFirst()); // throws
0N/A input.read(parameter.getSecond()); // throws
0N/A input.close(); // throws
0N/A return TrueChurchBoolean.singleton();
0N/A }
0N/A public AChurchBoolean caseFalse(Pair<File, byte[]> parameter) throws IOException {
0N/A return FalseChurchBoolean.singleton();
0N/A }
0N/A }, new Pair<File, byte[]>(file, output));
0N/A }
0N/A}