使用泛型从 jruby 调用抽象 java class
Call abstract java class from jruby with a generic
目前在 Jruby 中编写类似 java class 时遇到问题。
示例:
在Java中:
public class Client extends ClientConnection<ChannelType> {
//do some stuff
}
在 Jruby 中:
class Client < Java::'package_name'::ClientConnection
//do some stuff
end
重写客户端时不知道如何在 Jruby 代码中传递 ChannelType class class
简短的版本是,不幸的是你不能。
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 中编写类似 java class 时遇到问题。
示例:
在Java中:
public class Client extends ClientConnection<ChannelType> {
//do some stuff
}
在 Jruby 中:
class Client < Java::'package_name'::ClientConnection
//do some stuff
end
重写客户端时不知道如何在 Jruby 代码中传递 ChannelType class class
简短的版本是,不幸的是你不能。
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.