1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/funcInterfaces/Helper.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,138 @@ 1.4 +/* 1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/*SAM types: 1.28 + 1. An interface that has a single abstract method 1.29 + 2. Having more than one distinct methods, but only one is "real", the others are overriden public methods in Object - example: Comparator<T> 1.30 + 3. Having more than one methods due to inheritance, but they have the same signature 1.31 + 4. Having more than one methods due to inheritance, but one of them has a subsignature of all other methods 1.32 + a) parameter types compatible 1.33 + b) return type substitutable 1.34 + c) thrown type not conflicting with the thrown clause of any other method 1.35 + d) mixed up 1.36 + 5. Type-dependent SAM types 1.37 + non-SAM types: 1.38 + 6. An interface that has a single abstract method, which is also public method in Object 1.39 + 7. Having more than one methods due to inheritance, and none of them has a subsignature of all other methods 1.40 +*/ 1.41 + 1.42 +import java.util.List; 1.43 +import java.util.Collection; 1.44 +import java.sql.SQLException; 1.45 +import java.sql.SQLTransientException; 1.46 +import java.util.concurrent.TimeoutException; 1.47 +import java.io.*; 1.48 + 1.49 +interface A {int getOldest(List<Number> list);} 1.50 +interface B {int getOldest(List list);} 1.51 +interface C {int getOldest(List<?> list);} 1.52 +interface D {int getOldest(List<Integer> list);} 1.53 +interface E {int getOldest(Collection<?> collection);} 1.54 +//Not SAM type, case #7 1.55 +interface DE extends D, E {} 1.56 + 1.57 +interface Foo {int getAge(Number n);} 1.58 +interface Bar {int getAge(Integer i);} 1.59 +//Not SAM type, case #7 1.60 +interface FooBar extends Foo, Bar {} 1.61 + 1.62 +//Not SAM type, case #6 1.63 +interface Planet {boolean equals(Object o);} 1.64 + 1.65 +// SAM type interfaces: 1.66 +// type #2: 1.67 +//only one abstract non-Ojbect method getAge() 1.68 +interface Mars<T> extends Planet {int getAge(T t);} 1.69 +//only one abstract non-Ojbect method increment() 1.70 +interface Jupiter { 1.71 + boolean equals(Object o); 1.72 + String toString(); 1.73 + int increment(int i); 1.74 +} 1.75 + 1.76 +// type #3: 1.77 +interface X {int getTotal(List<String> arg);} 1.78 +interface Y {int getTotal(List<String> strs);} 1.79 +//SAM type ([List<String>], int, {}) 1.80 +interface XY extends X, Y {} 1.81 +//SAM type ([List<String>], int, {}) 1.82 +interface XYZ extends X, Y, XY {} 1.83 + 1.84 +// type #4 a): 1.85 +//SAM type ([List], int, {}) 1.86 +interface AB extends A, B {} 1.87 + 1.88 +// type #4 b): 1.89 +interface F {Number getValue(String str);} 1.90 +interface G {Integer getValue(String str);} 1.91 +interface H {Serializable getValue(String str);} 1.92 +interface I {Object getValue(String str);} 1.93 +//SAM type ([String], Integer, {}) 1.94 +interface FGHI extends F, G, H, I {} 1.95 + 1.96 +interface J {List<Number> getAll(String str);} 1.97 +interface K {List<?> getAll(String str);} 1.98 +interface L {List getAll(String str);} 1.99 +interface M {Collection getAll(String str);} 1.100 +//SAM type ([String], List<Number>/List, {}) - the return type is flexible to some degree 1.101 +interface JK extends J, K {} 1.102 +//SAM type ([String], List<Number>/List, {}) 1.103 +interface JL extends J, L {} 1.104 +//SAM type ([String], List<Number>/List, {}) 1.105 +interface JKL extends J, K, L {} 1.106 +//SAM type ([String], List<Number>/List, {}) 1.107 +interface JKLM extends J, K, L, M {} 1.108 + 1.109 +// type #4 c): 1.110 +interface N {String getText(File f) throws IOException;} 1.111 +interface O {String getText(File f) throws FileNotFoundException;} 1.112 +interface P {String getText(File f) throws NullPointerException;} 1.113 +//SAM type ([File], String, {FileNotFoundException}) 1.114 +interface NO extends N, O {} 1.115 +//SAM type ([File], String, {}) 1.116 +interface NOP extends N, O, P {} 1.117 + 1.118 +interface Boo {int getAge(String s) throws IOException;} 1.119 +interface Doo {int getAge(String s) throws SQLException;} 1.120 +//SAM type ([String], int, {}) 1.121 +interface BooDoo extends Boo, Doo {} 1.122 + 1.123 +// type #4 d): 1.124 +interface Q {Iterable m(Iterable<String> arg);} 1.125 +interface R {Iterable<String> m(Iterable arg);} 1.126 +//SAM type ([Iterable], Iterable<String>/Iterable, {}) 1.127 +interface QR extends Q, R {} 1.128 + 1.129 +interface U {Collection foo(List<String> arg) throws IOException, SQLTransientException;} 1.130 +interface V {List<?> foo(List<String> arg) throws EOFException, SQLException, TimeoutException;} 1.131 +interface W {List<String> foo(List arg) throws Exception;} 1.132 +//SAM type ([List<String>], List<String>/List, {EOFException, SQLTransientException}) 1.133 +interface UV extends U, V {} 1.134 +// SAM type ([List], List<String>/List, {EOFException, SQLTransientException}) 1.135 +interface UVW extends U, V, W {} 1.136 + 1.137 +// type #5: 1.138 +// Not a SAM because sam-ness depends on instantiation of type-variables 1.139 +interface Qoo<T> {void m(T arg);} 1.140 +interface Roo<S extends Number> {void m(S arg);} 1.141 +interface QooRoo<T1, T2 extends Number, T3> extends Qoo<T1>, Roo<T2> {}