gpt4 book ai didi

jruby - 使用泛型从 jruby 调用抽象 java 类

转载 作者:行者123 更新时间:2023-12-04 03:08:44 31 4
gpt4 key购买 nike

目前在 Jruby 中编写类似的 java 类时遇到问题。

示例:

在 Java 中:

 public class Client extends ClientConnection<ChannelType> {

//do some stuff

}

在 Jruby 中:

class Client < Java::'package_name'::ClientConnection

//do some stuff

end

重写Client类时不知道如何在Jruby代码中传递ChannelType类

最佳答案

简短的版本是,不幸的是你不能。

JRuby wiki 在这里这样解释 ( https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#beware-of-java-generics ):

If a Java class is defined with Java generics, the types are erased during compilation for backwards compatibility. As a result, JRuby will have problems with automatic type conversion. For example, if you have a Map, it will be seen as a simple Map, and JRuby will not be able to determine the correct types using reflection.

关于jruby - 使用泛型从 jruby 调用抽象 java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46887800/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com