Java 8’s orElse not working as expected

The arguments for a method are always evaluated before the method is called. You want orElseGet which takes a Supplier that will only be invoked if the Optional is not present: private Field getField(Class<?> clazz, String p) { return Arrays.stream(clazz.getDeclaredFields()) .filter(f -> p.equals(f.getName())) .findFirst() .orElseGet(() -> getField(clazz.getSuperclass(), p)); }

Swift nil has a numeric value?

I believe what is happening is that the literal 1 is being implicitly typecast to the Int? type by the comparison to nil. For those who aren’t used to Swift, I’ll explain a little further. Swift has a concept called “optionals”, which can either have a value or be nil. (For anyone familiar with Haskell, … Read more