Chapter 5, Exercises 1-2
Chapter 5, Exercise 1
1. Write a program that creates an ArrayList object without explicitly importing java.util.*.
object c5x1 {
def main ( args: Array[String] ) = {
var ar : java.util.ArrayList = _;
}
}
Chapter 5, Exercise 2
2. In the section labeled "package: the library unit",
turn the code fragments concerning mypackage into a compiling
and running set of Java files.
Well, s/Java/Scala/...
Choice (a) is simply to refer to MyClass with a qualified reference:
c5x2a.scala:
package x;
object c5x2a {
def main ( args: Array[String] ) = {
var m = new mypackage.MyClass();
}
}
Choice (b) is to import MyClass from its package:
c5x2b.scala:
package x;
import mypackage._;
object c5x2b {
def main ( args: Array[String] ) = {
var m = new MyClass();
}
}
Both of them refer to
c5x2z.scala:
package mypackage;
class MyClass { }
10:41:01 PM