Last active
August 29, 2015 14:05
-
-
Save alalwww/43a4fb450620814a180e to your computer and use it in GitHub Desktop.
IntelliJ IDEAでなんかエラー扱いになることがあるコードのサンプル。Optionalのmapの中でもっかいmapを行ってる部分で、エラー扱いになってしまう。(コンパイルは通る)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Optional; | |
public class Sample { | |
static final Sample instance = new Sample(); | |
Optional<Any1> get() { | |
return Optional.of(new Any1()); | |
} | |
static class Any1 { | |
Optional<Any2> get() { | |
return Optional.of(new Any2()); | |
} | |
} | |
static class Any2 { | |
String value = "value"; | |
} | |
static String hoge() { | |
return instance.get() | |
.map(any1 -> { | |
return any1.get() | |
.map(any2 -> any2.value) // 時々any2のtypeが不明になって、valueが見つからずがエラーになる | |
.orElse(null); | |
}) | |
.orElse(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
試したのは IntelliJ IDEA 13.1.4
Build #IU-135.1230, built on July 21, 2014
なお、eclipseではエラーにはならなかった模様。
IDEAのjava8解析がおかしいっぽい。