What is the best solution to avoid instantiations inside loops? By CAST we are checked our code and now we wont to solve the problem.
Part of code are follow
List<Long> darkList = new ArrayList<>();
for (Threshold thresholdObj : threshold) {
DarkDTO dto = new DarkDTO();
dto.setID(1L);
darkList.add(dto);
}
The problem is in DarkDTO dto = new DarkDTO();
line
How can I avoid avoid instantiations inside loops?