import java.util.*; class Foo { void test(Optional opt) { opt.filter(x -> x instanceof String) .map(s -> ((String) s).substring()) } }