简体   繁体   English

从R传递java arraylist对象

[英]passing java arraylist object from R

I am a freshman,hehe there are more questions... how can i creat a java-class type object in R for example ,there is a java class definition below: 我是大一新生,还有更多问题...例如,如何在R中创建Java类类型的对象,下面有一个Java类定义:


public class Bond{
  public String secid;
  public int paycycle;
  public float couprate;
  public Date vdate;

  public Bond(String secid,int paycycle,float couprate,Date vdate)
    {
        this.secid = secid;
        this.paycycle = paycycle;
        this.couprate = couprate;
        this.vdate = vdate;

    }
}

I intend to passing a Bond object to java function,actually,it's ArrayList object,i have no idea how to acheive,can you give me some idea,thanks!!! 我打算将Bond对象传递给java函数,实际上,它是ArrayList对象,我不知道该如何实现,谢谢。

If you need to pass an object as an argument to Java method, then you need to create this object as Java object with .jnew . 如果需要将对象作为参数传递给Java方法,则需要使用.jnew将此对象创建为Java对象。 On the R side you can use a list to represent the fields of a Java object, but you can't pass such object to Java via .jcall . 在R端,您可以使用列表来表示Java对象的字段,但不能通过.jcall将此类对象传递给Java。

Considering your comment below, maybe you need to rethink your approach to the problem you are trying to solve. 考虑下面的评论,也许您需要重新考虑您要解决的问题的方法。 Think about which parts of the solution have to be coded in Java and which in R. Then think how you can interface these two parts with minimal amount of coupling. 考虑该解决方案的哪些部分必须用Java进行编码,哪些必须用R进行编码。然后考虑如何以最小的耦合量来连接这两个部分。 You may be able to code your complete solution in Java, or pass the data between Java and R via text file instead of trying to create solution which passes objects back and forth between different languages. 您也许可以用Java编写完整的解决方案,或者通过文本文件在Java和R之间传递数据,而不必尝试创建在不同语言之间来回传递对象的解决方案。 If this works, you don't need rJava. 如果可行,则不需要rJava。

The way I see it, rJava is primarily used when you want to take advantage of some algorithms or methods implemented in Java while calling them from R. The data is passed back and forth as primitives or arrays of primitives, not as custom objects. 从我的角度来看,rJava主要用于您想要从R调用它们时利用Java中实现的某些算法或方法的优点。数据作为基元或基元数组而不是自定义对象来回传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM