Computer Science Canada

[Scala] Java anti-patterns

Author:  wtd [ Sun Feb 10, 2008 2:18 am ]
Post subject:  [Scala] Java anti-patterns

The following is a reasonable pattern Java code falls into:

code:
class Foo {
    private int bar;
    private String baz;
    private double qux;
   
    public Foo(int bar, String baz, double qux) {
        this.bar = bar;
        this.baz = baz;
        this.qux = qux;
    }
   
    public int getBar() {
        return bar;
    }
   
    public String getBaz() {
        return baz;
    }
   
    public double getQux() {
        return qux;
    }
}


And here's the equivalent Scala:

code:
class Foo(val bar: Int, val baz: String, val qux: Double)


: