https://kotlinlang.org logo
Title
a

am

08/28/2019, 9:30 AM
Is it good way to define constants as a top level declaration with
internal
key word eg
internal const NAME_FOO:String = " "
class Foo{
}
a

Amirul Zin

08/28/2019, 9:39 AM
IMHO, if you’re not in a multi module project/library project, the
internal
marker is functionally a code noise
a

am

08/28/2019, 10:34 AM
Its not used any where except its class declaration,and test
t

thanksforallthefish

08/28/2019, 10:36 AM
internal
marks visibility to the entire module, so every other file in the same module would have access to it, disregarding other forms of packaging. I think that is what Amirul means, if you have a single module,
internal
practically means
public
(and in kotlin everything is
public
by default)
👍 2
in your case, it should be privare imo, but that is my preference, I don't reuse constants in test if possible, as changing them will not break tests most probably (I got burned in the past with constant used for http path, changed the path inadvertently, nothing signaled me the error, broke qa environment)