| Article: |
10 Reasons We Need Java 3.0 | |
| Subject: | Functional Methods | |
| Date: | 2002-12-16 19:14:24 | |
| From: | anonymous2 | |
|
I suggest addition of functional (as in "functional programming" i. e. without side effects). This could be specified by method modifier "functional" (in the language) and by special bit in the "access_flags" field of "method_info" structure in class file (there are some unassigned bits).
|
||
Showing messages 1 through 2 of 2.
-
Functional Methods
2004-01-07 17:52:56 anonymous2 [View]
Why not just use a language that was functional at its inception (e.g. Haskell)?
-
Functional Methods (correction)
2002-12-16 19:45:51 anonymous2 [View]
Sorry, Java code in the examples does not look as expected. I'll try to use HTML tags.
"Traditional approach"
void addNumber(int[] arr,int n)
{
for(int i=0;i<arr.length;i++)
{
arr[i]+=n;
}
}
"Functional" approach:
functional int[] addNumber(int[] arr,int n)
{
int[] arret=new int[arr.length];
for(int i=0;i<arr.length;i++)
{
arret[i]=arr[i]+n;
}
return arret;
}
</pre>


