Chapter 5, Exercise 8
Sorry, got busy for a few days. (SLO Road Trip and MTB campout at Montaña de Oro State Park.) So Ex.8 asks
In the section titled "Class access" you'll find code
fragments describing mylib and Widget. Create this library,
then create a Widget in a class that is not part of the
mylib package.
THECLAPP's entry is here. However, it looks like we're not quite in synch: what he
calls ex. 9 is ex. 8 in the version of TiJ that I have
(3rd ed., Revision 4.0).
Well, each code fragment is barely
more than a one-line header. But anyway,
here is c5x8_mylib.scala:
package c5x8_mylib;
// Classes are public by default in Scala.
class Widget {
Console.println( "Creating a c5x8_mylib.Widget." );
def boo = Console.println( "Boo!" );
}
And then here is the guy who creates that Widget:
package x;
object c5x8_main {
def main ( args: Array[String] ) = {
val w = new c5x8_mylib.Widget;
w boo;
}
}
Note that I call w.boo without the dot, using "boo" as
if it were a postfix unary operator. Whee. Also note that
the constraint mentioned in the text of this section
(only one public class per compilation unit, with its name
having to match the source file name) does not apply in Scala.
And also note that a Scala plugin for Eclipse has been announced
on the Scala mailing list. Details later.
11:42:00 PM