sdcf4j icon indicating copy to clipboard operation
sdcf4j copied to clipboard

Collections in command handler methods

Open Vampire opened this issue 8 years ago • 4 comments

Where an array is allowed in a command handler method, also allow a Collection.

Vampire avatar Dec 16 '17 23:12 Vampire

The problem is, that you cannot (afaik) get the type of the used Generic during runtime.

Bastian avatar Dec 24 '17 10:12 Bastian

I thought so too, but I'd say it is possible to a certain degree, otherwise you wouldn't be able to cast lambdas you register to Discord4J to a concrete IListener<MessageReceivedEvent>.

Discord4J for this uses https://github.com/jhalterman/typetools, maybe you can use that or borrow some code there if the license allows.

And if it is not possible, you might maybe support it by some convention on parameter names, requiring people to use the Java 8+ functionality that paramter names are stored in the class files if they want to use it like that.

Vampire avatar Dec 24 '17 22:12 Vampire

Is there even a real advantage to support Collections as well? Sure, it's always good to have some options, but in this case I don't think it justifies the effort. Is there a real use case in which a collection would be superior compared to an array?

Bastian avatar Dec 24 '17 22:12 Bastian

Where is it not? :-D You could e. g. use streams easily on them, without having to use Arrays.stream(). You can of course also convert it to a collection or stream yourself with the helper methods. But you could also parse Longs and roles and users yourself, but the lib does it for you if you want. :-)

Vampire avatar Dec 24 '17 22:12 Vampire