S
S
Sergey Semenko2017-05-23 16:22:47
Java
Sergey Semenko, 2017-05-23 16:22:47

How to help Java decide on types?

There is a code:

listenForWhisper(socketManager.<MessagingUser>presenceChannel("dialog-" + dialog.getId()),
    WhisperEvent.EVENT_TYPING, TypingEvent.class);

listenForWhisper method:
public <T> SocketChannel listenForWhisper(SocketPresenceChannel<T> channel, String name,
                                          Class<? extends WhisperEvent<T>> event) {
        if (!channels.containsKey(channel.getName())) {
            channels.put(channel.getName(), channel);
        }
        return channel.listenForWhisper(name, event);
    }

As you can see, I have to explicitly specify the data type, which looks rather dubious. I can write like that, it’s not difficult for me, but what about the readability of such code?
Or is it better not to bring it up?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question