2
的常量我嘗試以下,但得到了一個錯誤「錯誤的參數數目(2 0)」:紅寶石 - 相同類型的類
class Rating
NOOB = Rating.new(1, "U A NOOB")
def initialize(rating, message)
@rating = rating
@message = message
end
end
什麼是寫在紅寶石下面的相同呢? (這是我做的枚舉的方式)
public class Rating {
public static Rating NOOB = new Rating(1, "U SO NOOB");
public static Rating EXPERT = new Rating(2, "U A PRO BRO");
private int rating;
private String message;
public Rating(int rating, String message) {
this.rating = rating;
this.message = message;
}
...
}
這並不是解釋者不知道它需要的論據。而是調用默認的'initialize',它取零參數。 – sawa