Skip to main content

The def keyword

2 replies [Last post]
shagus
Offline
Joined: 2007-05-10
Points: 0

The following class example is from the javafx tutorial. Chapter1.
http://openjfx.java.sun.com/current-build/doc/reference/overview.html
Take a look at the def keyword. What does it mean? When was it added?
Thank you.

<br />
    class Rectangle {</p>
<p>     def sides: Integer = 4;<br />
     var width: Integer;<br />
     var height: Integer;</p>
<p>     function grow(): Void {<br />
          grow(1);<br />
     }</p>
<p>     function grow(amount: Integer): Void {<br />
          width += amount;<br />
          height += amount;<br />
     }</p>
<p>}<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kram
Offline
Joined: 2007-10-23
Points: 0

I got this from the doco:

The def keyword introduces a variable that cannot be assigned to, overridden, or set in an object literal; a def can be bound, however, making it not a true constant

found:
http://openjfx.java.sun.com/current-build/doc/reference/types.html

enjoy!

shagus
Offline
Joined: 2007-05-10
Points: 0

Yes it has been added recently in Build #2301 (Jul 23, 2008 11:32:09 PM)
Fixed JFXC-607: Variables defined using 'def' should be not be assignable

Thank you for your response.