Hey In my library (that will be distributed) I hav...
# announcements
i
Hey In my library (that will be distributed) I have simple Kotlin data class where some of the properties are nullable
Copy code
// Kotlin class
data class Test(
val name: String,
val lastName :String?
)
Copy code
// Generated Java class src
public final data class Test public constructor(name: kotlin.String, lastName: kotlin.String) { 
}
Since this class will be also used from Java is there any way to include
Nullable
and
NonNull
annotations in generated the code for the properties? Something like this:
Copy code
// Generated Java class src
public final data class Test public constructor(@NonNull name: kotlin.String, @Nullable lastName: kotlin.String) { 
}
(I mostly care about
NonNull
): The main drive for this behaviours is that now I can create new instance of
Test
class from Java and pass null values
new Test(null, null)
without any indication that this is wrong/undesired usage- I believe with annotations IDE would display error/waring 🤔
r
When I use IntelliJ to view the bytecode, and decompile it, the
@NotNull
and
@Nullable
annotations are there.
The decompiled to java class looks like this: https://gist.github.com/Mahoney/accc9252472e93632727d9c8a85815d2
i
You are right @robstoll annotations are there - I think I found a bug in Kotlin Plugin or decompiler - I am investigating
r
You probably meant @Rob Elliot 😉
👍 2