introduce functional: convert to lambda when applicable (IDEA-174018)

This commit is contained in:
Anna Kozlova
2017-06-07 17:56:35 +03:00
parent d65ff6ad81
commit 101ae53c3b
7 changed files with 26 additions and 36 deletions

View File

@@ -3,12 +3,8 @@ import java.util.function.Supplier;
class Test {
void foo() {
if (true) {
Supplier<String> supplier = new Supplier<String>() {
public String get() {
return "Hello, world";
}
};
System.out.println(supplier.get());
Supplier<String> stringSupplier = () -> "Hello, world";
System.out.println(stringSupplier.get());
}
}
}

View File

@@ -2,11 +2,7 @@ import java.util.function.Supplier;
class Test {
void foo() {
Supplier<String> supplier = new Supplier<String>() {
public String get() {
return "Hello, world";
}
};
System.out.println(supplier.get());
Supplier<String> stringSupplier = () -> "Hello, world";
System.out.println(stringSupplier.get());
}
}

View File

@@ -4,12 +4,8 @@ class Test {
String myName;
void foo() {
if (true) {
Consumer<String> consumer = new Consumer<String>() {
public void accept(String myName) {
System.out.println("Hello, world " + myName);
}
};
consumer.accept(myName);
Consumer<String> stringConsumer = myName -> System.out.println("Hello, world " + myName);
stringConsumer.accept(myName);
}
}
}

View File

@@ -1,11 +1,7 @@
class Test {
void foo(String name) {
System.out.println("Hello, ");
Runnable runnable = new Runnable() {
public void run() {
System.out.println(name);
}
};
Runnable runnable = () -> System.out.println(name);
runnable.run();
}
}

View File

@@ -3,12 +3,8 @@ import java.util.function.Consumer;
class Test {
void foo(String s) {
if (true) {
Consumer<String> consumer = new Consumer<String>() {
public void accept(String s) {
System.out.println("Hello, world " + s);
}
};
consumer.accept(s);
Consumer<String> stringConsumer = s1 -> System.out.println("Hello, world " + s1);
stringConsumer.accept(s);
}
}
}

View File

@@ -3,13 +3,11 @@ import java.util.function.Consumer;
class Test {
void foo(String s) {
if (true) {
Consumer<String> consumer = new Consumer<String>() {
public void accept(String s) {
System.out.println("Hello, world " + s);
System.out.println();
}
Consumer<String> stringConsumer = s1 -> {
System.out.println("Hello, world " + s1);
System.out.println();
};
consumer.accept(s);
stringConsumer.accept(s);
System.out.println();
}