Chainfire/libsuperuser

Request: put nullable annotations for all functions parameters

AndroidDeveloperLB opened this issue · 6 comments

For example, when we use OnCommandResultListener or OnCommandResultListener2 , I can see it's with "?" when used in Kotlin, because it doesn't know if it's nullable or not.

I understand the title, but I'm not following the description. I have barely done any Kotlin, please elaborate on the problem.

@Chainfire The "?" on Kotlin means about the same as the annotation "Nullable".

I've added the annotations (push soon) but I haven't used them before so I hope they're correct :)

Well, if you used Kotlin, you'd be forced to use them ( nothing in case it's non-nullable, and "?" in case it's nullable), and then you could see in both build time (errors might appear) or during runtime (crashes in case it doesn't match).

Of course, Kotlin has its own annoyances, some don't exist on Java...

Yes, I understand. Unfortunately I'm currently not working in either Java or Kotlin myself. Kotlin was on the to-do list for my next project, so I went through all the tutorials to get started last year, but my job suddenly went in the Python+C direction so I haven't gotten a chance to do anything real with Kotlin yet. I don't remember enough to do anything in it quickly right now, and I don't have the time right now to get back into it.

I mean, the annotations are probably correct, they're not that complicated after all, but please let me know how they work out for you.

Kotlin is very similar to Java in various ways.
And, I got to learn much from it by just converting existing code via the IDE tool itself.
The most common issue with conversion from Java to Kotlin is nullability, so before converting it's very recommended to add nullability annotations, so that the converted will know what to do (it's quite stupid in this matter, no matter how many clues there are about nullable stuff there are there).

I made a task to myself, to convert most (or entirely) of the files on my spare time apps to Kotlin. This week I've finished it, with just one class in one of my apps that I failed to convert (it's quite a messy class, which I'm not really the one who made it originally).

I try it at work too, but this is a much larger task, because the app we work on has at least 1000 of Java files ...

Usually code in Kotlin is shorter than on Java, and there is a chance that it will run better than Java starting from Android P in some cases (here and here) .