k47.cz    — každý den dokud se vám to nezačne líbit
foto Praha výběr povídky kultura | twitter FB


Java boilerplate vs. Scala 📷

publikováno 9. 12. 2010 od k47

1. ukázka pochází odsud

// Java
class Employee
{
    private final String name;
    private final int age;
    private final int salary;

    public Employee(String name, int age, int salary)
    {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName()
    {
        return this.name;
    }

    public int getAge()
    {
        return this.age;
    }

    public int getSalary()
    {
        return this.salary;
    }

    @Override
    public String toString()
    {
        return String.format("%10s(%2d) ... $%d", this.getName(), this.getAge(), this.getSalary());
    }
}


// ekvivalentní třída ve Scale
class Employee(val name: String, val age: Int, val salary: Int) {
  override def toString() = String.format("%10s(%2d) ... $%d", name, age.asInstanceOf[Object], salary.asInstanceOf[Object])
}


// Where is your God now?

2. ukázka je odtud

// Java
import java.util.*

class Item {
	int i;
    public Item(int i) {
        this.i = i;
    }
}

class Pair {
    public Item item1;
    public Item item2;

    public Pair(int i1, int i2) {
        this.item1=new Item(i1);
        this.item2=new Item(i2);
    }
}

public class Test {
    public static void main(String[] args) {
        System.console().readLine("press enter to begin");

        int n = Integer.parseInt(args[0]);
        List list = new ArrayList();
        for (int i=0; i
píše k47 & hosté, kontakt: ascii@k47.cz