Compound data type: Difference between revisions

Add NetRexx implementation
(Add NetRexx implementation)
Line 814:
<pre>
point := Point{x := 3, y := 4};
</pre>
 
=={{header|NetRexx}}==
Like Java, NetRexx uses the <tt>class</tt> instruction to create compound types. Unlike Java; NetRexx provides keywords to automatically generate getters and setters for <tt>class</tt> properties and will automatically generate intermediate methods based on defaults provided in method prototypes.
<lang NetRexx>/* NetRexx */
options replace format comments java crossref symbols nobinary
 
class RCompoundDataType
method main(args = String[]) public static
pp = Point(2, 4)
say pp
return
 
class RCompoundDataType.Point -- inner class "Point"
properties indirect -- have NetRexx create getters & setters
x = Integer
y = Integer
 
method Point(x_ = 0, y_ = 0) public -- providing default values for x_ & y_ lets NetRexx generate intermediate constructors Point() & Point(x_)
this.x = Integer(x_)
this.y = Integer(y_)
return
 
method toString() public returns String
res = 'X='getX()',Y='getY()
return res
</lang>
'''Output:'''
<pre>
X=2,Y=4
</pre>
 
Anonymous user