1
Promise<List<WrapSpec>> wrapSpecPromise = new Job() {
                @Override
                public List<WrapSpec> doJobWithResult() throws Exception {
                    return PkgLoad.findDistinctWrapSpecBetweenDates(pkgLine, startDate, endDate);               
                }
            }.now();

Is it possible to pass the values pkgLine, startDate, endDate into this method? Thanks for any help.

EDIT: Is this something that is advised against? Or not. Thanks.

    for ( final PkgLine pkgLine : pkgLineList ) {


            Promise<List<WrapSpec>> distinctWrapPromise = new Job() {

                @Override
                public List<WrapSpec> doJobWithResult() throws Exception {
                    return PkgLoad.findDistinctWrapSpecBetweenDates( pkgLine, startDate, endDate );
                }
            }.now();
            promiseList.add( distinctWrapPromise );
        }
animuson
  • 53,861
  • 28
  • 137
  • 147
Drew H
  • 4,699
  • 9
  • 57
  • 90
  • There is also another way like in the below link [Passing parameters without using final][1] [1]: http://stackoverflow.com/a/12206542/1168603 –  Apr 08 '13 at 09:19

2 Answers2

5

Yes, if they are declared final in the calling block

final PkgLine pkgLine = ...;
final Date startDate = ...;
final Date endDate = ...;

Promise<List<WrapSpec>> wrapSpecPromise =
  new Job() {
    @Override
    public List<WrapSpec> doJobWithResult() throws Exception {
      return
        PkgLoad.findDistinctWrapSpecBetweenDates(
          pkgLine,
          startDate,
          endDate
        );               
    }
  }.now();
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
  • Thanks. I do remember reading that a while back. I've made an edit to my post. Is this something that makes sense? – Drew H Jul 17 '11 at 00:38
2

Into the doJobWithResult method, no, unless you want to change the Job interface/class. However, they can be variables defined either in the enclosing method or class and used that way. If local variables, they must be final to use in an anonymous inner class, as shown in Alexander's answer.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199