chore: organize homework into first-part directory
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
@@ -0,0 +1,27 @@
|
||||
import java.util.Objects;
|
||||
|
||||
final class ImmutableClass {
|
||||
ImmutableClass(MutableClass firstField, String secondField, Integer thirdField) {
|
||||
this.firstField = new MutableClass(Objects.requireNonNull(firstField));
|
||||
this.secondField = secondField;
|
||||
this.thirdField = thirdField;
|
||||
}
|
||||
|
||||
public MutableClass getFirstField() {
|
||||
return new MutableClass(firstField);
|
||||
}
|
||||
|
||||
public String getSecondField() {
|
||||
// Копировать не нужно так как String является Immutable
|
||||
return secondField;
|
||||
}
|
||||
|
||||
public Integer getThirdField() {
|
||||
// Копировать не нужно так как Integer является Immutable
|
||||
return thirdField;
|
||||
}
|
||||
|
||||
private final MutableClass firstField;
|
||||
private final String secondField;
|
||||
private final Integer thirdField;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class MutableClass {
|
||||
MutableClass(int value) {
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
// Конструктор копирования
|
||||
public MutableClass(MutableClass other) {
|
||||
this.value = other.value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private int value;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Homework 01
|
||||
|
||||
Реализовать свой иммутабельный класс, который будет
|
||||
внутри себя содержать поле с изменяемым классом.
|
||||
|
||||
## UPDATED
|
||||
|
||||
Иммутабельный класс должен содержать минимум 3 различных поля, включая поле с
|
||||
изменяемым классом.
|
||||
Reference in New Issue
Block a user