Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Why does Java not allow default function arguments ?

  Asked By: Maria    Date: Jun 08    Category: Java    Views: 1053
  

I asked this question in Sun's Java forum without success.
Here it is again:

------------------------------------------------------
Why does Java not allow default function arguments ?
Was this a conscious decision made by the Java inventors ?
If so, why ? (I found that C# also does not allow default
arguments....is it bad ?)

I know that the same 'effect' can be achieve using
function overloading but I am interested as to why
this 'feature' was omitted from the language.
------------------------------------------------------

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Dannon Jones     Answered On: Jun 08

I suppose they omitted it because it basically is a form of
method overloading  and would make it confusing ie.

void myTestMethod(int x,int y=1){}

is more confusing than:

void myTestMethod(int x){myTestMethod(x,0); }
void myTestMethod(int x,int y){}

 
Didn't find what you were looking for? Find more on Why does Java not allow default function arguments ? Or get search suggestion and latest updates.




Tagged: