例如,尝试从Ruby访问Kafka的Scala / Java API(在require和Rjb :: load步骤之后)
ProducerData = Rjb::import('kafka.javaapi.producer.ProducerData')
topic = "test"
msg = "message"
producer_data = ProducerData.new_with_sig('Ljava.lang.String;Ljava.lang.String;',topic,msg)
在Kafka API中,ProducerData方法定义为:
class ProducerData[K, V](private val topic: String,
private val key: K,
private val data: java.util.List[V])
运行文件后的结果是:
./test-rjb.rb:30:in `new_with_sig': Constructor not found (RuntimeError)
如何正确访问具有泛型类型签名的类?