import java.util.Map; import java.util.Set; import java.io.IOException; import java.util.function.IntFunction; import my.unknown.pkg.Anno; import my.unknown.pkg.MyInterface; import my.unknown.pkg.Cls; import my.unknown.UnusedClass; import my.unknown.Value; import my.unknown.UsedInClassObject; import my.unknown.UsedInMethodRef; public class Simple { int test() { test().run(); return 0; } void refsInResolvedClass(String s) { System.out.println(String.STATIC); s.trim(); s.dream(); System.out.println(s.field); } void callKnownCtor(Cls cls) { new IOException(cls); // No three-arg ctor anyway new IOException(cls, cls, cls); } void testImports(Cls.UnusedClass inner) { var x = Value; System.out.println(UsedInClassObject.class); Runnable r = UsedInMethodRef::foo; } void testMethodRef() { Runnable r1 = UsedInMethodRef::new; Runnable r2 = UsedInMethodRef[]::new; IntFunction<UsedInMethodRef[]> r3 = UsedInMethodRef[]::new; Runnable r4 = String::blahblah; Runnable r5 = String::getBytes; Runnable r6 = "hello"::trim; } void refsInUnresolvedClass(Cls s) { s.hashCode(); s.dream(); System.out.println(s.field); System.out.println(Cls.STATIC); } void assign(Unknown u) { String s = u; Number n = u; Unknown2 u2 = u; Unknown2 u3 = s; } void knownTypes(String s) { Boolean b = s; } void method(String s, Object obj) {} private void methodThrows() throws IOException { System.out.println(); } void methodCall(Unknown u) { method("Hello", u); method(u, "Hello"); method(u, u); } @Anno void annotated(MapAnno String> map) {} void cast(String s, Unknown u) { Unknown2 u2 = (Unknown)u; String s2 = (String)u; } void instanceOf(String s, Unknown u) { if (u instanceof Unknown2) {} if (u instanceof String) {} if (s instanceof Unknown) {} } void testEquality(Unknown u, Unknown2 u2, char c, boolean b) { if (u == u2) {} if (u != u2) {} if (c == b) {} } @Anno(Cls.CONST) void testAssign(Unknown u) { u.field = 2; } void callOnArray(Unknown u) { u.foo()[0].blah(); } void initArray() { Cls[] array = {Cls.createCls()}; } void callOverloaded(Set<Cls> mySet) { overloaded(Cls.getValue()); mySet.toArray(Cls.EMPTY_ARRAY); } void varTest() { var x = Cls.getSomething(); x.getSomethingElse(); var y = x; var z = y.getSomethingCompletelyDifferent(); z.getFromZ(); var t = t; } void overloaded(int x) {} void overloaded(boolean x) {} void useInner() { Clss.Inner cls = new Clss.Inner(); Clss.Inner[] result = (Clss.Inner[]) cls.toArray(12); } void testThrow(Cls cls) { try { cls.unknownM(); } catch (Cls x) { } catch (IOException | RuntimeException ex) { } } void testThrow2() { try { declaredUnknownException(); } catch (Cls x) {} } void testThrow3() { // We don't know whether Cls is checked or not declaredUnknownException(); } void declaredUnknownException() throws Cls {} void testConcat(Cls cls) { System.out.println("hello " + cls.getSomething() + "!!!"); } static class Clss implements MyInterface { void run() { foo(bar); } static class Inner extends Cls { } } }