Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 67 jvm languages Null safety Gosu provides several operators to save you from NullPointer exceptions and from writing boilerplate code So instead of writing this if location null return location Address else return null you can write this return location Address Named arguments and optional parameters You can provide default values for constructor and function parameters to make the parameters optional to the caller function printList list List String separator String printList myList printList myList Both calls to printList are valid The first one uses the default separator value You can also name arguments when calling a function function configure lux false awd false ac false configure awd true Intervals Interval or Range expressions are Gosus way of expressing a contiguous set of numbers dates names or anything with a Comparable interface they are denoted by the operator var range A M print range contains Jones true print range contains Smith false In addition if the elements in the interval also represent a sequence you can iterate over it Heres a simple way to print the numbers 1 to 10 for i in 1 10 print i You can also set the step and unit if applicable A biweekly date sequence var span date1 date2 step 2 unit WEEKS And you can reverse the order and express open or closed endpoints to the range 10 1 reverse order start end start inclusive end exclusive Delegation As an alternative to class inheritance Gosu provides support for composition in the form of interface delegation interface ClipboardPart function cut function copy function paste class MyWindow extends Window implements ClipboardPart delegate _ myPart represents ClipboardPart new ClipboardPartMixin this Basically this delegate statement hooks up the ClipboardPartMixin with MyWindows implementation of ClipboardPart No other work is necessary all ClipboardPart methods automatically forward to the delegate No more boilerplate compositional code
You must have JavaScript enabled to view digital editions.