How about add declaration file support?

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
}

This can already be achieved by using Nullability annotations in the Java source code.

you can’t modify thirdparty library code(eg. jdk)——if i can modify them, i will convert them to kotlin directly instead of use annotations

In Intellij you can already annotate third party libraries using external annotations

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)

I can think of a few ways of working round that.

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: https://git.kpi.fei.tuke.sk/jan.juhar/connotator/

Probably a few more ways, those are just some which popped into my head.