Skip to content

Commit a8aeeb5

Browse files
hansonrhansonr
authored andcommitted
Java 8 stream tweaks
working: // http://www.javainuse.com/java/java8_method_References List<String> myList = Arrays.asList("b1", "a2", "a1", "c2", "c1"); System.out.println("\n\n------- stream().map().forEach() using lambda expressions -------"); myList.stream().map(s -> s.toUpperCase()).forEach(s -> System.out.print(s + " ")); System.out.println("\n\n------- stream().map().sorted().forEach() using Class::method method reference --------"); myList.stream().map(String::toUpperCase).sorted().forEach(System.out::print); // https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/ System.out.println("\n\n------- stream().filter().map().sorted().forEach() --------"); myList.stream() .filter(s -> s.startsWith("c")) .map(String::toUpperCase) .sorted() .forEach(System.out::print); System.out.println("\n");
1 parent 9a8f94c commit a8aeeb5

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed
-21 Bytes
Binary file not shown.
-21 Bytes
Binary file not shown.

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5730,13 +5730,12 @@ public static void dumpStack() {
57305730
* c = new Test()::test2;
57315731
*/
57325732
public boolean visit(ExpressionMethodReference node) {
5733-
addAnonymousFunctionWrapper(true);
5734-
buffer.append("var $this$=");
5735-
node.getExpression().accept(this);
5736-
buffer.append(";");
5733+
buffer.append("(function($this$){");
57375734
ITypeBinding binding = node.resolveTypeBinding();
57385735
processNewAnonInstance(node, null, binding, null, LAMBDA_METHOD);
5739-
addAnonymousFunctionWrapper(false);
5736+
buffer.append("})(");
5737+
node.getExpression().accept(this);
5738+
buffer.append(")");
57405739
return false;
57415740
}
57425741

@@ -5805,7 +5804,6 @@ private void addLambdaMethod(ASTNode lnode, IMethodBinding mBinding) {
58055804
buffer.append("/*lambdaM*/");
58065805
// Function<Object,Test> iaCreator2= Test::new;
58075806
ExpressionMethodReference node = (ExpressionMethodReference) lnode;
5808-
// mBinding = node.resolveMethodBinding();
58095807
String name = getMethodNameOrArrayForDeclaration(mBinding, false, false, true);
58105808
processMethodDeclaration(mBinding, name, null, null, false, false, true);
58115809
removeVariableFinals(mBinding, null);

0 commit comments

Comments
 (0)