Код: Выделить всё
class Date {
private final int month;
private final int day;
private final int year;
public BasicDate(int m, int d, int y) { //constructor
this.month = m;
this.day = d;
this.year = y;
}
public int month() {
return month;
}
public int day() {
return day;
}
public int year() {
return year;
}
public String toString() {
return month() + "/" + day() + "/" + year();
}
}
Код: Выделить всё
class Date{
private final int value;
public SmallDate(int m, int d, int y) {
this.value = y*512 + m*32 + d;
}
public int month() {
return (value / 32) % 16 ;
}
public int day() {
return value % 32 ;
}
public int year() {
return value / 512 ;
}
public String toString() {
return month() + "/" + day() + "/" + year();
}
}
потому что их использование ограничено. сложно (и даже спорно) даже для экспертов, особенно в
в сочетании с другими продвинутыми функциями языка, которые мы ценим (обобщениями и итераторами).
Что это такое функции? И как я могу поддерживать эти две реализации одновременно?
Подробнее здесь: https://stackoverflow.com/questions/786 ... lient-code