Thursday 14 April 2011

Scala and Java

HelloWorldScala.scala
package net.pizey.scala.toy

class HelloWorldScala {
  def m(message: String) {
    println(message + " - from scala")
  }
}

object HellowWorld {
  def main(args: Array[String]) {
    val s = new HelloWorldScala()
    val j = new HelloWorldJava()
    s.m("Hello world")
    j.m("Hello world")
  }
}

HelloWorldJava.java
package net.pizey.scala.toy;

public class HelloWorldJava {

  public void m(String message) {
    System.out.println(message + " - from java");
  }

  public static void main(String[] args) {
    HelloWorldScala s = new HelloWorldScala();
    HelloWorldJava j = new HelloWorldJava();
    s.m("Hello world");
    j.m("Hello World");
  }
}

Both output
Hello world - from scala
Hello World - from java