IDEA-191856 "Replace Optional.isPresent() condition with functional style expression" creates bad code when used with Type Promotion

This commit is contained in:
Tagir Valeev
2018-05-24 12:44:33 +07:00
parent 2fe3ee616e
commit 0269e72a79
5 changed files with 70 additions and 20 deletions

View File

@@ -0,0 +1,11 @@
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class Main {
void test(Optional<String> foo) {
double bar = foo.map(s -> s.length() * 1.2).orElse(0.0);
}
}

View File

@@ -0,0 +1,12 @@
// "Replace Optional.isPresent() condition with functional style expression" "false"
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class Main {
void test(Optional<String> foo) {
int defaultValue = 0;
double bar = foo.isPresent<caret>() ? foo.get().length() * 1.2 : defaultValue;
}
}

View File

@@ -0,0 +1,11 @@
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class Main {
void test(Optional<String> foo) {
double bar = foo.isPresent<caret>() ? foo.get().length() * 1.2 : 0;
}
}