Fix virtual method variant of invokedynamic reloading

Issue: #87
This commit is contained in:
Andy Clement
2015-06-28 19:30:52 -07:00
parent 773d25019b
commit 1eb2a1263c
13 changed files with 598 additions and 86 deletions

View File

@@ -0,0 +1,34 @@
package basic;
public class LambdaL {
static {
System.out.println("original static initializer");
}
public LambdaL() {
System.out.println("original instance");
}
public interface Foo { String m(String s); }
public String getFoo(String s) {
System.out.println("in first foo");
return "foo"+s;
}
public static void main(String[] args) {
run();
}
public static String run() {
String res= new LambdaL().run2();
System.out.println(res);
return res;
}
public String run2() {
Foo f = this::getFoo;
return f.m("a");
}
}

View File

@@ -0,0 +1,27 @@
package basic;
public class LambdaL2 {
public interface Foo { String m(String s, String t); }
public String getFoo(String s, String t) {
System.out.println("in second foo");
return "foo"+s+t;
}
public static void main(String[] args) {
run();
}
public static String run() {
String res= new LambdaL2().run2();
System.out.println(res);
return res;
}
public String run2() {
Foo f = this::getFoo;
return f.m("a","b");
}
}

View File

@@ -0,0 +1,32 @@
package basic;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class LambdaM {
// public interface Foo { String m(String s); }
// public String getFoo(String s) {
// return "foo"+s;
// }
public static void main(String[] args) {
run();
}
public static String run() {
return new LambdaM().run2();
}
public String run2() {
List<String> list = new ArrayList<>();
list.add("test3");
Map m = list.stream().collect(Collectors.toMap(String::length, Function.identity()));
return m.toString();
}
}

View File

@@ -0,0 +1,30 @@
package basic;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class LambdaM2 {
public static void main(String[] args) {
run();
}
public static String run() {
return new LambdaM2().run2();
}
public String run2() {
List<String> list = new ArrayList<>();
list.add("test3");
Map m = list.stream().collect(Collectors.toMap(this::foo, Function.identity()));
return m.toString();
}
public int foo(String input) {
return input.length()*2;
}
}

View File

@@ -0,0 +1,35 @@
package basic;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class LambdaN {
public static void main(String[] args) {
run();
}
public static String run() {
return new LambdaN().run2();
}
public String run2() {
List<String> list = new ArrayList<>();
HelperN h = new HelperN();
list.add("test3");
Map m = list.stream().collect(Collectors.toMap(h::foo, Function.identity()));
return m.toString();
}
}
class HelperN {
public int foo(String input) {
return input.length()*3;
}
}

View File

@@ -0,0 +1,39 @@
package basic;
public class StaticMethodReference {
public static String staticMethod(String s1) {
System.out.println("in 1st static Method");
return "static" + s1;
}
public interface Bar { String sm(String s);}
public interface Foo { String m(String s); }
public String getFoo(String s) {
return "foo"+s;
}
public static void main(String[] args) {
run();
}
public static String run() {
StaticMethodReference l = new StaticMethodReference();
String r = l.run3();
System.out.println(r);
return l.run2();
}
public String run2() {
Foo f = this::getFoo;
return f.m("a");
}
public String run3() {
Bar b = StaticMethodReference::staticMethod;
return b.sm("sa");
}
}

View File

@@ -0,0 +1,39 @@
package basic;
public class StaticMethodReference2 {
public static String staticMethod(String s1, String s2) {
System.out.println("in 2nd static Method");
return "static" + s1 + s2;
}
public interface Bar { String sm(String s, String s1);}
public interface Foo { String m(String s); }
public String getFoo(String s) {
return "foo"+s;
}
public static void main(String[] args) {
run();
}
public static String run() {
StaticMethodReference2 l = new StaticMethodReference2();
String r = l.run3();
System.out.println(r);
return l.run2();
}
public String run2() {
Foo f = this::getFoo;
return f.m("a");
}
public String run3() {
Bar b = StaticMethodReference2::staticMethod;
return b.sm("sa", "sb");
}
}