将值传递给内部类方法?

Dre*_*w H 1 java inner-classes playframework

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

是否可以将值pkgLine,startDate,endDate传递给此方法?谢谢你的帮助.

编辑:这是建议反对的东西吗?或不.谢谢.

    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 );
        }
Run Code Online (Sandbox Code Playgroud)

Ale*_*yak 5

是的,如果它们final在调用块中声明

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();
Run Code Online (Sandbox Code Playgroud)