Bastian / sdcf4j

A simple Discord command framework for Java
GNU Lesser General Public License v3.0
63 stars 22 forks source link

Allow Optionals as command handler method arguments #27

Open Vampire opened 6 years ago

Vampire commented 6 years ago

Allow Optional<GroupChannel> and so on as parameters and directly put the Optional in there instead of using orElse(null), mapping should be by type parameter if possible or if not, by parameter name if possible (In Java 8 you can use a java compiler switch to make the parameter names available during runtime)

Bastian commented 6 years ago

There's the same problem as in #24 and I'm not even sure if I like this idea. Optionals usually shouldn't be used as parameters, even though this is some kind of special use case. The big advantage of Optionals (which is the reason I use them in Javacord 3) is, that you can immediately see whether a method might return a null value or not. This doesn't apply for method parameters. If someone really needs the methods of Optional, one can just use Optional.ofNullable(...) to convert it.

Vampire commented 6 years ago

Yeah, I also have seen the inspection of IJ in the meantime, but I really wonder why they are not good as parameters, except for type erasure vs. reflective usage. But same here, of course you can do it yourself, the lib just did it for you in other cases. You are free to not do it, is was just an idea I had and thought might be useful. :-)