Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call abstract java class from jruby with a generic

Tags:

jruby

Currently facing an issue while writing a similar java class in Jruby.

Example:

In Java:

 public class Client extends ClientConnection<ChannelType> {

  //do some stuff

 }

In Jruby:

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

//do some stuff

end

Don't know how to pass ChannelType class in Jruby code while rewriting the Client class

like image 802
Surajit Chongder Avatar asked Dec 31 '25 10:12

Surajit Chongder


1 Answers

The short version is, you can't unfortunately.

The JRuby wiki explains it as such here (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.

like image 78
Armin Braun Avatar answered Jan 06 '26 16:01

Armin Braun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!