Java代码
- public class MyJava{
-
- @Test
- public void test(){
- MyKotlin.getValue(null);
- }
-
- }
- java.lang.NullPointerException: Parameter specified as non-null is null: method com.zhangyu.myapplication.MyKotlin.getValue, parameter id
-
- at com.zhangyu.myapplication.MyKotlin.getValue(Mete.kt)
- at com.zhangyu.myapplication.MyJava.test(MyTest.java:9)
- object MyKotlin{
-
- @JvmStatic
- fun getValue(id: String) {
- println("getValue: $id")
- }
- }
- @JvmStatic
- public static final void getValue(@NotNull String id) {
- Intrinsics.checkNotNullParameter(id, "id");
- String var1 = "getValue: " + id;
- boolean var2 = false;
- System.out.println(var1);
- }
- public static void checkNotNullParameter(Object value, String paramName) {
- if (value == null) {
- throwParameterIsNullNPE(paramName);
- }
- }
- class MyKotlin{
- @Test
- fun test() {
- //调用java
- val str: String = MyJava.getValue()
- println(str)
- }
- }
- public class MyJava{
- public static String getValue() {
- return null;
- }
- }
- java.lang.NullPointerException: MyJava.getValue() must not be null
-
- at com.zhangyu.myapplication.MyKotlin.test(MyKotlin.kt:9)