Java 8 lambda testcode

This commit is contained in:
Andy Clement
2014-02-17 16:23:53 -08:00
parent 9774e2a0d4
commit f9a8252317
14 changed files with 275 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaB {
public interface Foo { long m(int i); }
public static void main(String[] args) {
run();
}
public static long run() {
Foo f = null;
f = (i) -> i*33;
return f.m(3);
}
}

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaB2 {
public interface Foo { long m(int i); }
public static void main(String[] args) {
run();
}
public static long run() {
Foo f = null;
f = (i) -> i*44;
return f.m(4);
}
}

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaC {
public interface Boo { long m(int i,int j); }
public static void main(String[] args) {
run();
}
public static long run() {
Boo f = null;
f = (i,j) -> i*j;
return f.m(3,2);
}
}

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaC2 {
public interface Boo { long m(int i,int j); }
public static void main(String[] args) {
run();
}
public static long run() {
Boo f = null;
f = (i,j) -> i+j;
return f.m(3,2);
}
}

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaD {
public interface Boo { String m(int i,String s, int j, boolean b); }
public static void main(String[] args) {
run();
}
public static String run() {
Boo f = null;
f = (i,j,k,l) -> ""+l+i+k+j;
return f.m(3,"abc",42,true);
}
}

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaD2 {
public interface Boo { String m(int i,String s, int j, boolean b); }
public static void main(String[] args) {
run();
}
public static String run() {
Boo f = null;
f = (i,j,k,l) -> j+(i*k)+l;
return f.m(3,"def",88,true);
}
}

View File

@@ -0,0 +1,23 @@
package basic;
public class LambdaE {
public interface Boo { String m(char s); }
public static void main(String[] args) {
run();
}
public static String run() {
int i = 4;
Boo f = null;
f = (c) -> {
StringBuilder buf = new StringBuilder();
for (int j=0;j<i;j++) {
buf.append(c);
}
return buf.toString();
};
return f.m('a');
}
}

View File

@@ -0,0 +1,23 @@
package basic;
public class LambdaE2 {
public interface Boo { String m(char s); }
public static void main(String[] args) {
run();
}
public static String run() {
int i = 8;
Boo f = null;
f = (c) -> {
StringBuilder buf = new StringBuilder();
for (int j=0;j<i;j++) {
buf.append(c);
}
return buf.toString();
};
return f.m('a');
}
}

View File

@@ -0,0 +1,33 @@
package basic;
public class LambdaF {
public int fieldOne = 7;
public String concatenator(char ch, int number) {
StringBuilder buf = new StringBuilder();
for (int j=0;j<number;j++) {
buf.append(ch);
}
return buf.toString();
}
public interface Boo { String m(char s); }
public static void main(String[] args) {
run();
}
public static String run() {
return new LambdaF().x();
}
public String x() {
int i = 4;
Boo f = null;
f = (c) -> {
return concatenator(c,fieldOne);
};
return f.m('a');
}
}

View File

@@ -0,0 +1,34 @@
package basic;
public class LambdaF2 {
public int fieldOne = 3;
public String concatenator(char ch, int number) {
StringBuilder buf = new StringBuilder();
for (int j=0;j<number;j++) {
buf.append(ch);
buf.append(':');
}
return buf.toString();
}
public interface Boo { String m(char s); }
public static void main(String[] args) {
run();
}
public static String run() {
return new LambdaF2().x();
}
public String x() {
int i = 4;
Boo f = null;
f = (c) -> {
return concatenator(c,fieldOne);
};
return f.m('a');
}
}

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaG {
interface Boo { int m(); }
public static void main(String[] args) {
run();
}
public static int run() {
Boo f = null;
f = () -> 99;
return f.m();
}
}

View File

@@ -0,0 +1,16 @@
package basic;
public class LambdaG2 {
interface Boo { int m(); }
public static void main(String[] args) {
run();
}
public static int run() {
Boo f = null;
f = () -> 44;
return f.m();
}
}

View File

@@ -0,0 +1,34 @@
package basic;
public class LambdaH {
public interface Foo { int m(); }
public int fieldOne = 7;
public int concatenator(int a, int b) {
return a*b;
}
public static void main(String[] args) {
run();
}
public static int run() {
int count = 0;
count += ((Foo)()->7).m();
count += new LambdaH().x();
count += ((Foo)()->21).m();
return count;
}
public int x() {
int i = 4;
Foo f = null;
f = () -> {
return concatenator(i,fieldOne);
};
return f.m();
}
}