Anti-pattern name for the raw usage of `List<List<Object>>` instead of some data transfer objects `List<DTO>`

131 Views Asked by At

Is there any known anti-pattern name for the raw usage of List<Object> that is actually List<List<Object>> instead of some data transfer objects List<DTO>?

class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        final List<Person> people = getPeople();
        people.forEach(p -> System.out.println(p.getName()));
        System.out.println("--------");
        final List<Object> objects = getObjects();
        objects.forEach(o -> System.out.println(((List<Object>) o).get(0)));
    }

    public List<Person> getPeople() {
        return Arrays.asList(
            new Person("john", 33),
            new Person("jeff", 22),
            new Person("jack", 11)
        );
    }

    public List<Object> getObjects() {
        return Arrays.asList(
            Arrays.asList("john", 33),
            Arrays.asList("jeff", 22),
            Arrays.asList("jack", 11)
        );
    }
}

class Person {
    private final String name;
    private final int age;

    Person(final String name, final int age) {
        this.name = name;
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public String getName() {
        return name;
    }
}
0

There are 0 best solutions below