-
-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove lateinit usage in Main.kt #156
Conversation
Yeah that is not pretty at all :), my other thought was to introduce a backing field so we do not need the |
Yep, agree. I'll explore some other approaches later today. 👍
…On Wed, Jul 5, 2017 at 9:59 AM Artur Bosch ***@***.***> wrote:
Yeah that is not pretty at all :), my other thought was to introduce a
backing field so we do not need the !! everywhere?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#156 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF4k0WGAcCeFTXA9q2Hr5-51DF-qxt0Rks5sK0JWgaJpZM4ON8ed>
.
|
e02c6f6
to
6751f5a
Compare
@@ -96,6 +99,9 @@ class Main { | |||
private fun validateCli(cli: Main): List<String> { | |||
val violations = ArrayList<String>() | |||
with(cli) { | |||
if (project == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned this is not really necessary as JCommander
already requires this parameter to be set. Let me know how you feel about this one also being here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then delete this lines and do a test run with the CLI and we are happy :)
Updated the PR by using the backing field and making |
I'm just curious why |
Because it misleads you not using a safer way to initialize a variable (constructor injection or delegation). When I started programming in Kotlin I often used Ofc in our case it seems kind of odd to replace one keyword with a backing field, but this due to the nature of many annotation heavy libraries (jcommander). Ofc if you know what you do The tradeoff here is like Suppress annotation vs backing field :D |
Resolves #132
This follows the recommendation from the issue. But overall I'm not sure if its nicer to have 3
!!
in the code compared to thelateinit var
.Probably also the null check in
validateCli
is not really useful as the project parameter is alreadyrequired = true
and thus JCommander will already throw an exception if the parameter is not specified.