Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完善kotlin支持,支持传递函数引用变量 #29

Closed
wants to merge 1 commit into from

Conversation

AkaAny
Copy link

@AkaAny AkaAny commented Feb 6, 2023

原有的代码是支持kotlin的,kotlin里的Class::method语法走的是这个分支,并且可以正常工作

  try {
            Method method = func.getClass().getDeclaredMethod("writeReplace");
            return new ReflectLambdaMeta((java.lang.invoke.SerializedLambda) ReflectionKit.setAccessible(method).invoke(func));
        } catch (Throwable e) {
            // 5. 反射失败使用序列化的方式读取
            return new ShadowLambdaMeta(SerializedLambda.extract(func));
        }

但是如果加一层引用,比如val dtoGetAddressesRef=UserDTO::getAddresses,用这个语法,拿到的method name就会包含类似于$lambda1的后缀(这段代码在test项目里可以找到)

这个后缀会导致fieldMap.get返空,产生报错,报错位置是mybatis-plus-join-core/1.4.2.2/mybatis-plus-join-core-1.4.2.2-sources.jar!/com/github/yulichang/wrapper/interfaces/QueryLabel.java:54

fun getFromFuncVar(userID:String):UserDTO{
        val dtoGetAddressesRef=UserDTO::getAddresses
        val pred=MPJLambdaWrapper<UserDO>()
            .selectAll(UserDO::class.java)
            .addressesSubPredicate(dtoGetAddressesRef,UserDO::getUserID) //这是个扩展函数,封装了selectCollection和join
            .eq(UserDO::getUserID,userID)
        val result= mapper.selectJoinOne(UserDTO::class.java,pred)
        return result
    }

我对kotlin那些语法糖展开的了解也比较有限,如果实现有误,或者有更好的实现,please feel free to comment and I will be grateful.

@yulichang
Copy link
Owner

很棒, 不过我对kt也不是很了解, 等我了解完kt再处理这个pr, 应该不会太久

@AkaAny
Copy link
Author

AkaAny commented Feb 28, 2023

很棒, 不过我对kt也不是很了解, 等我了解完kt再处理这个pr, 应该不会太久

谢谢,looking forward to ur reply~

@yulichang yulichang closed this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants