(*******************************) object HelloWorld { def main(args: Array[String]) { println("Chapito les tepos") } // This is a comment } (********* Exercice 1 *********) class Complex(val real : Double, val imag : Double) { def +(that: Complex) = new Complex(this.real + that.real, this.imag + that.imag) def -(that: Complex) = new Complex(this.real - that.real, this.imag - that.imag) override def toString = real + " + " + imag + "i" } object Complex { def I = new Complex(0, 1) implicit def Double2Complex(value : Double) = new Complex(value, 0.0) } object Implicits { def main(args: Array[String]) = { import Complex._ // needed for the implicits val c1 = new Complex(14, 2); println("Complex (new Complex) : " + c1) val c2 = Complex.I; println("Complex (attribute I) : " + c2) } } class OrderedComplex (override val real : Double, override val imag : Double) extends Complex(real, imag) with Ordered[OrderedComplex] { def compare(that : OrderedComplex) : Int = { if (this.real < that.real) -1 else 1 } } (********* Exercice 2 *********) class Hello { public void print_int(int i) { System.out.println("Just an integer : " + i); } public void print_nothing() { System.out.println("That's nothing"); } public static void main(String [] args) { System.out.println("Howdy ?"); Hello h = new Hello(); h.print_nothing(); h.print_int(42); h.print_nothing(); System.out.println("Hasta la vista ..."); } } aspect PinceCoupante { pointcut tournevis(): execution(* Tournevis.*(..)); before() : tournevis() { System.out.println("Advice from : " + thisJoinPoint.getSignature().getName());} } pointcut justints(int x) : execution(* Hello.*(int)) && args(x); before(int x) : justints(x) { /* ... */ } (********* Exercice 3 *********) final static boolean ENABLED = true; pointcut marteau() : if (PinceCoupante.ENABLED) && // ... (********* Exercice 4 *********) public aspect CaptainAgeAspect { pointcut setAge(Integer i): call(* setAge(..)) && args(i); Object around(Integer i): setAge(i) { System.out.println("Before that, he was " + i + "years old."); Integer newi = (Integer) proceed(i*2); System.out.println("After, he got older : " + newi + "years."); return newi; }} (********* Exercice 5 *********)