cardillo / joinery

Data frames for Java
https://joinery.sh
GNU General Public License v3.0
697 stars 167 forks source link

Extra argument apply? #53

Closed junajo10 closed 7 years ago

junajo10 commented 8 years ago

Hi,

How can i add an extra argument numShares? public void getStaticProfile(int numShares) { this.service.getDf().apply(new Function<Object,Number>() { public Number apply(Object value) { BigDecimal b = new BigDecimal(value.toString()); System.out.println(b); return b.multiply(new BigDecimal(numShares)); } });

}

Rgds,

JJ

cardillo commented 8 years ago

You can make numShares visible to the apply method scope by marking it final. This doesn't specifically allow an extra argument to apply, but it will solve your immediate problem.

junajo10 commented 8 years ago

Thanks, but numShares is an argument that i set from another function, i can not fixed as final becuase it must be dynamic.

cardillo commented 7 years ago

See below, having a final variable reference is not the same as having a variable which is constant.

public void getStaticProfile(final int numShares) {
  this.service.getDf().apply(new Function<Object,Number>() {
    public Number apply(Object value) {
      BigDecimal b = new BigDecimal(value.toString());
      System.out.println(b);
      return b.multiply(new BigDecimal(numShares));
  }
});