我正在学习Scala,我无法弄清楚如何在Scala中最好地表达这个简单的Java类:
public class Color {
public static final Color BLACK = new Color(0, 0, 0);
public static final Color WHITE = new Color(255, 255, 255);
public static final Color GREEN = new Color(0, 0, 255);
private final int red;
private final int blue;
private final int green;
public Color(int red, int blue, int green) {
this.red = red;
this.blue = blue;
this.green = green;
}
// getters, et cetera
}
Run Code Online (Sandbox Code Playgroud)
我最好的是以下内容:
class Color(val red: Int, val blue: Int, val green: …Run Code Online (Sandbox Code Playgroud)