#401 Код-ревью сервиса получения комментариев

Компании:
Иннотех
Темы:
SpringОсновы SpringКод ревью

Сделать код-ревью:

import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;

@Service
public class NewService {

    private static ArrayList<String> comments = new ArrayList<>();
    private static final int commentsCount = 5;

    public List<String> getComments() {
        comments = new ArrayList<>();
        String response = call();
        try {
            log.debug("getComments: " + response);
            for (int i = 0; i < commentsCount; i++) {
                comments.add(new JSONObject(response).getJSONArray(i).getString("comment"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return comments;
    }

    /**
     * Example JSON:
     * 
     * [
     *   {
     *     "fullName": "Иванов Иван Иванович",
     *     "comment": "qqqqq"
     *   },
     *   {
     *     "fullName": "Петров Петр Петрович",
     *     "comment": "wwwww"
     *   }
     * ]
     * 
*/ private String call() { ResponseEntity<String> responseEntity = new RestTemplate().exchange( "http://localhost:9103/api/comments", HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), String.class ); return responseEntity.getBody(); } }

Разбор вопроса

Ментор
Ответь как на реальном собеседовании. Я задам уточняющие вопросы, а затем сравню твой ответ с эталонным и покажу точность в %.
Войди, чтобы начать диалог Ментор ведёт диалог по текущему вопросу и учитывает предыдущие сообщения.
Войти