R
R
Romka212018-12-30 22:34:17
Java
Romka21, 2018-12-30 22:34:17

Java method implementation?

Friends tell me how to do such things in java.
Here are methods like:

public static List<User> findAll() {
        List<User> list = (List<User>)  HibernateSessionFactoryUtil.getSessionFactory().openSession().createQuery("From "+User.class.getSimpleName()).list();
        return list;
    }

public static List<Group> findAll() {
        List<Group> list = (List<Group>)  HibernateSessionFactoryUtil.getSessionFactory().openSession().createQuery("From "+Group.class.getSimpleName()).list();
        return list;
    }

Is it possible to pass some construction at the input to make the method universal and not do List list = (List) , it turns out that for each object I have a findAll() method, which is essentially the same in functionality, but differs in the description of objects. Only the implementation in the instanceOf method comes up in the vote

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Alexandrov, 2018-12-30
@jamakasi666

Generics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question