sdcf4j icon indicating copy to clipboard operation
sdcf4j copied to clipboard

Allow Optionals as command handler method arguments

Open Vampire opened this issue 8 years ago • 2 comments

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)

Vampire avatar Dec 16 '17 23:12 Vampire

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.

Bastian avatar Dec 24 '17 22:12 Bastian

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. :-)

Vampire avatar Dec 24 '17 23:12 Vampire