Anvil | Smiths Smiths | Register Register | Login Login |
Search:
Show links Show tools Show tree | Previous document Next document | njet.org > Anvil > Documentation > Language reference > Expressions > Primaries > New operator

New operator

New operator creates and returns new instance of class. Identifier after new keyword must refer into class. New instance of class is created and constructor called.

Although ``new´´ can be dropped from expression without affecting its result (the same either way) it is quite different expression: Without ``new´´ expression is call emulation to anvil.runtime.Type pointing to class, which happens to work so that when called, new instance is created and constructor called. ``newInstance()´´ method can also be called on type to get the same results.

Named parameters and splices (@) are used with a same way as in calls.

There is a special closure call which will take only one parameter, an inline function, which is placed instead of parameter list. No other parameters are possible with closure call.

  new-expr := "new" identifierclass "(" parameters ")" 
  new-expr := "new" identifierclass  inline-functionparameter   
  param := [ symbolname "=" | "@" ] expr 
  parameters := param ( "," param )* 
See also  | Primaries  | Classes  | Grammar
Contributes notes:
Add a note
What's new | Anvil