Will this cause confusion to use interchangeably terms "function" vs "method" in java7 and java8?
I know that java 8 introduced some concept like lambda calculus, which allows inserting small bits of functional paradigm to be used.
Functions as in lambda calculus, functional programming.
When speaking about Java-8 you may use the word "function" to refer to the functional interface (interface with single abstract method), the class implementing such interface or the expression of the functional interface type (including lambda expression or method reference). You should not however call methods as functions. This become even more important than in previous Java versions as if you see the word "function" in Java-7 related discussion, you can assume that the "method" was meant. But in Java-8 people may think that you are speaking about functional interface, not about method.
So it's ok to say:
The
Stream.map
method accepts a function as a parameter.
Or
A
Collector
interface aggregates four functions: supplier, accumulator, combiner and finisher.
Or
I pass the
Objects::nonNull
function to theStream.filter
method.
But the following would sound confusing:
I get a strange exception when I use
Math.sqrt
function.
You probably may get away with interchanging function and method during non formal talk but if you want to be precise keep in mind that:
void
return type is not a real value).In general - you now know that there's a difference between a function and a method so just keep it in mind and use proper term from now on.
Functions are different from methods irrespective of java version. Though with java 8 these terms are more meaningful now. With earlier versions of java also, you can see functions as the static methods as these are not bound to the class data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With