DEV Community

Discussion on: Java functional vs OO programing

Collapse
 
sarahk profile image
Sarah

If by functional programming you mean the new lib introduced in Java 8 - yes I use it all the time. But you have to still use OOP, are you saying the two are mutally exclusive?

I use lambdas, method references, Consumer, Supplier, Function, Optional types, Streams (collect, reduce, map, filter, etc) and I'm not aware of any performance issues.

Collapse
 
jiayanguo profile image
jguo • Edited

I am not saying they are mutually exclusive. Let's use an example.

Functional:

public Supplier<String> someMethod() {
return () -> "Hello!"
}

or

callMethod(() -> "Hello!")

More OOP style.

private Supplier<String> hello = () -> "Hello!";

public Supplier<String> someMethod() {
return hello;

or 

callMethod(hello);