val webRootDirectory = Paths.get("src", "main", "resources", "web").toAbsolutePath()
idea complains “declaration has type inferred from a platform call which can lead to unchecked nullability issue”
when i add a
!!
, it instead complains “unnecessary non null assertion (!!) on a non null receiver of type path”
s
spand
04/20/2020, 10:53 AM
I usually specify the type on the variable to get rid of the platform type
c
christophsturm
04/20/2020, 10:57 AM
that fixes it but its more verbose. also the behavior is probably a bug
m
Mike
04/20/2020, 11:58 AM
Both of Idea's complaints are warnings to indicate there is something you should pay attention to. If you're happy with it, then you can either Suppress the warning to clearly indicate to others that you've thought about it, and are ok with it, ignore it, or as suggested, explicitly put the type.
Yes, it's more verbose, BUT it's also very clear to others, and the compiler, what you expect to happen.
Less code isn't always a good thing, and I'm slowly changing my perspective on 'put type as little as possible'.
If you ALWAYS use IDEA to read your code, and have type hints on, then they're unnecessary.
But if you're reviewing code in a text editor, or on GitHub/GitLab/Bitbucket etc, then you're left guessing at the types.