question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't differentiate between @A(int.class) and @A(Integer.class)

See original GitHub issue

Given the following Java code:

@MyAnnotation(int.class)
class B {
}

@MyAnnotation(Integer.class)
class C {
}

and the following KSP code

val clsB = resolver.getClassDeclarationByName("com.example.B")
val clsC = resolver.getClassDeclarationByName("com.example.C")

val annB = clsB!!.annotations.first().arguments.first().value
val annC = clsC!!.annotations.first().arguments.first().value

val equal = annB === annC

equal is true, which is surprising given that the underlying code is not and int.class == Integer.class would return false.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ting-yuancommented, Oct 12, 2022

can this criteria be reliably used to tell boxed/primitve types apart? Is there a guarantee, that this will always be the case?

Yes, it is documented so KSP needs to follow.

What if one uses java.lang.Integer explicitly in Kotlin?

It’ll be non-null java.lang.Integer. Only types in Java sources are mapped.

What if a method in Kotlin (override fun getInt(): Int) overrides a method from Java superclass (Integer getInt()) with an explicitly non-null return-type?

It’ll be non-null kotlin.Int for the Kotlin overrider and kotlin.Int! for the Java overridee.

0reactions
Jeffsetcommented, Oct 9, 2022

In KSP, primitive types are NOT_NULL, while boxed types are PLATFORM.

Good point, but can this criteria be reliably used to tell boxed/primitve types apart? Is there a guarantee, that this will always be the case? What if one uses java.lang.Integer explicitly in Kotlin? What if a method in Kotlin (override fun getInt(): Int) overrides a method from Java superclass (Integer getInt()) with an explicitly non-null return-type?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between Integer and int in Java?
Integer refers to wrapper type in Java whereas int is a primitive type. Everything except primitive data ...
Read more >
Difference between an Integer and int in Java - Tutorialspoint
A Java both int and Integer are used to store integer type data the major difference between both is type of int is...
Read more >
Difference between Integer and int in Java [Practical Examples]
In Java, int is a primitive data type whereas Integer is a Wrapper class. In other words, int can store the values in...
Read more >
int vs Integer Java - Javatpoint
So, the main difference between the int and Integer is that the int is of primitive data type while the Integer is of...
Read more >
In Java, int is not a class, why have int.class this usage? What ...
Yes, in Java all wrapper classes are immutable, and String too. (thou you forgot to capitalise the name , it is “Integer” not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found