What Is The Difference Between Function And Method
What Is The Difference Between Function And Method
Collapse
X
-
Tags: None
-
There are different notions about functions and methods: a method in Java canOriginally posted by r035198xThe mathematicians that hang around this forum will probably tell you that a function is a method that returns exactly one value.
do what it wants: bake a cake for you, print "foo" on every paper page in your
printer until the printer is out of paper, attempt to format your harddisks and a
lot more usefull things. A function in Java can do the same but it must return
a value of a certain type.
A lot more restrictive (but very useful) functions are the 'referential transparent'
functions: those functions don't have side effects (no cake, no out of paper and
no fresh hard disks) and every time you call them with the same parameter
values they return the same value again and again. According to this definition
e.g. the Random.nextint( ) method is not a function.
Of course mathematics nags a bit further about, e,g. continuous functions,
bijective, injective, surjective functions, (primitive) recursive functions, computable
functions and the list goes on and on. Those mathematicians are loonies, there's
no need to pay any attention to them when you deal with Java.
kind regards,
JosComment
-
In Java, the preferred terminology is method. I don't know if the word "function" even appears in the Java Language Specification (JLS), although a Java programmer would know what you're talking about. Here is the relevant section, enjoy:
JLS: methodsComment
-
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).
This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.
MODERATORComment
Comment