| Java | Scala |
|---|---|
(mutable!) public class User {
private String name;
private List<Order> orders;
public User() {
orders = new ArrayList<Order>();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Order> getOrders() {
return orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
}
public class Order {
private int id;
private List<Product> products;
public Order() {
products = new ArrayList<Product>();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
}
public class Product {
private int id;
private String category;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
}
| (immutable!) case class User (name: String, orders: List[Order] = Nil) case class Order (id: Int, products: List[Product] = Nil) case class Product (id: Int, category: String) Initialisierung: val user = User(name = "Tim", orders= List( Order(id = 1, products = List( Product(id = 1, category="Tools"))))) Ändern (nur über Kopie!) user.copy(name = "Timo") |
Scala Pros & Cons
| Pro | Con |
|---|---|
|
|
Scala Code
Übungen & Workshops
Basics: https://github.com/DarkToast/scala-workshop
Übersicht coole Features: tbd
Übungen: https://github.com/DarkToast/scala-dojo
Scala Days 2016
- Videos: https://www.youtube.com/playlist?list=PLLMLOC3WM2r7kLKJPHKnyJgdiBGWaKlJf
- Meine Notizen: 2016 Scala Days