something like d.ts(typescript) or jni to help compiler recognize correct types in java files or jni libraries
Foo.java:
public class Foo {
public Integer bar(Long input) {
return input == null ? null : input.intValue();
}
public Object bar2() {
return "inaccurate type in thirdparty library";
}
public Integer iDontCare() {
System.out.println("keep this method return `Int!` because users do not care");
return null;
}
}
Foo.ktd
css Foo {
fun bar(Long? input): Int?
fun bar2(): String
}
then i need include annotations.xml in git and share to team/orgnization/open source project?
IDE based solution is not as good as lang based solution.
btw, it seems that annations can’t handle Foo.bar2 case(specific Object to accurate type)
First, you could add an extension function bar2String which wraps the original method call and casts the result. You might be able to have an annotation TM for this then use kapt or similar to generate the wrapper function.
Second, you could write an inline class to wrap the original entirely, if there are a lot of things to change.
Third, I don’t know, but maybe there are third-party tools which can use external annotations? I found this, but I don’t know if it’s a working thing: Ján Juhár / Connotator · GitLab
Probably a few more ways, those are just some which popped into my head.