Can't differentiate between @A(int.class) and @A(Integer.class)
See original GitHub issueGiven 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:
- Created 2 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, it is documented so KSP needs to follow.
It’ll be non-null
java.lang.Integer
. Only types in Java sources are mapped.It’ll be non-null
kotlin.Int
for the Kotlin overrider andkotlin.Int!
for the Java overridee.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?