Advertisement
DulcetAirman

lambda vs anon. class

Dec 29th, 2015
231
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. final Stream lengths = Arrays.stream(args).map(new Function<String, Integer>() {
  2.   @Override
  3.   public Integer apply(final String t) {
  4.         return check(t);
  5.   };
  6. });
  7.  
  8. results in:
  9.  
  10. Exception in thread "main" java.lang.IllegalArgumentException
  11.     at ch.fhnw.claudemartin.SomeClass.check(SomeClass.java:14)
  12.     at ch.fhnw.claudemartin.SomeClass$1.apply(SomeClass.java:33)
  13.     at ch.fhnw.claudemartin.SomeClass$1.apply(SomeClass.java:1)
  14.     at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  15.     at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
  16.     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
  17.     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
  18.     at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
  19.     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
  20.     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  21.     at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
  22.     at ch.fhnw.claudemartin.SomeClass.main(SomeClass.java:37)
  23.  
  24. ------------------------------------------------------------
  25.  
  26. Stream lengths = Arrays.stream(args).map(name -> check(name));
  27.  
  28. results in:
  29.  
  30. Exception in thread "main" java.lang.IllegalArgumentException
  31.     at ch.fhnw.claudemartin.SomeClass.check(SomeClass.java:14)
  32.     at ch.fhnw.claudemartin.SomeClass.lambda$0(SomeClass.java:29)
  33.     at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  34.     at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
  35.     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
  36.     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
  37.     at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
  38.     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
  39.     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  40.     at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
  41.     at ch.fhnw.claudemartin.SomeClass.main(SomeClass.java:38)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement