vmtrue
vmtrue

Reputation: 1774

Strange package name after desugaring

I use Android Studio 4.0 with coreLibraryDesugaringEnabled true

When I use LocalDateTime I see j$.time.LocalDateTime instead of java.time.LocalDateTime. Why is that?

example

val kClass = LocalDateTime::class
Log.d("TestApp","class: $kClass")

Upvotes: 1

Views: 173

Answers (1)

Ryan M
Ryan M

Reputation: 20197

In order for desugaring to work, the fully-qualified class name needs to be different than the "normal" one. If it weren't, then on newer versions of Android where that class exists, there would be two classes with the same name, and that can lead to unpredictable issues.

Thus, D8 replaces java with j$, a package name that cannot be expressed in Java, so it won't conflict with any classes you may have defined yourself.

For more information on how D8's desugar backports types like LocalDateTime, see this excellent blog post from Jake Wharton.

Upvotes: 4

Related Questions