Created
November 16, 2017 13:01
-
-
Save alexshavelev/8dbdfa35258f6e00441a8f1976905bb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task13.task1306; | |
/* | |
Баг в initializeIdAndName | |
1. Подумать, что в программе неправильно. | |
2. Вынести реализацию метода initializeIdAndName в класс User. | |
3. initializeIdAndName в классе User должен возвращать тип User. | |
4. Поправить программу, чтобы компилировалась и работала. | |
Требования: | |
1. Интерфейс DBObject должен содержать только объявление метода initializeIdAndName без реализации. | |
2. Реализуй метод initializeIdAndName в классе User. | |
3. Метод initializeIdAndName в классе User должен иметь тип возвращаемого значения User. | |
4. Метод initializeIdAndName должен присваивать значения полям id и name в соответствии с переданными ему параметрами. | |
*/ | |
public class Solution { | |
public static void main(String[] args) throws Exception { | |
System.out.println(Matrix.NEO); | |
System.out.println(Matrix.TRINITY); | |
} | |
static class Matrix { | |
public static DBObject NEO = new User().initializeIdAndName(1, "Neo"); | |
public static DBObject TRINITY = new User().initializeIdAndName(2, "Trinity"); | |
} | |
interface DBObject { | |
DBObject initializeIdAndName(long id, String name); | |
} | |
static class User implements DBObject { | |
long id; | |
String name; | |
@Override | |
public String toString() { | |
return String.format("User has name %s, id = %d", name, id); | |
} | |
@Override | |
public User initializeIdAndName(long id, String name) { | |
this.id = id; | |
this.name = name; | |
return this; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment