Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to set a default value for an argument variable

Tags:

Android function

PHP example:

function HaHa($a = "Test") {     print $a;  } 

The question is how to do it in android...

public void someFunction(int ttt = 5) {    // something } 

The solution above doesn't work, how can I do it?

Thanks!

like image 287
M.V. Avatar asked Apr 07 '11 12:04

M.V.


People also ask

Can we give default value to arguments?

Python allows function arguments to have default values.

How do you assign default values to variables?

The OR Assignment (||=) Operator The logical OR assignment ( ||= ) operator assigns the new values only if the left operand is falsy. Below is an example of using ||= on a variable holding undefined . Next is an example of assigning a new value on a variable containing an empty string.

What is a default parameter value?

In JavaScript, a parameter has a default value of undefined. It means that if you don't pass the arguments into the function, its parameters will have the default values of undefined .


1 Answers

No, Java does not support default values for function parameteres. There's an interesting post about borrowing language features here: http://java.dzone.com/news/default-argument-values-java

like image 157
Bendihossan Avatar answered Oct 12 '22 02:10

Bendihossan