views:

184

answers:

2

I saw a method in Action script that has a return type of *

public function f(s:String):*

what does this [*] means ?

+6  A: 

The * symbol means "untyped", meaning that the type can be anything (and that the value can be undefined). Using the asterisk has the same effect as not specifying the type at all, but it's good form to use it in order to be explicit about your intention. See the language reference for more info.

hasseg
+6  A: 

That answer is not 100% correct. There is no "untyped" and there is only a small difference between * and Object, because one could argue that Object means untyped as well since every type extends from Object. However * implies the undefined value and Object not. A big difference! This is useful for dynamic languages because this means a property of an Object can be undefined which is different from defined and null.

So for instance y is undefined in { x: null } and x is defined but without a value. And you can make use of that:

var yesNoMaybe: *;

yesNoMaybe = true;
yesNoMaybe = false;
yesNoMaybe = undefined;
Joa Ebert
The concept of "untyped" does exist; the language reference uses that term in the first sentence of the description of the `*` special type: "Specifies that a property is untyped.".
hasseg
You sould read my response again. What is the difference for you as a programmer between "var x: Object = 1; var y: * = 1; var z = 1"? All are "untyped" in the sense that every type extends from the object type and has no specific type at runtime. However y and z can be undefined. That is a big difference, also in terms of speed! A lot of people think it is great to return "*" for untyped things but they are better off using Object.
Joa Ebert
You're not wrong at all in your suggestions on best practices here. My intention is simply to clarify what the term "untyped" means; using it in a way that is not aligned with the definition used in the language reference could be confusing.
hasseg