2

I know that there are some libraries which allow using Java 8 features such as streams and lambda expressions but what I need is to use a library that was developed in Java 8.

To be more precise, there's a method which returns java.util.stream instance and I need to iterate over this stream. I tried to use retrostreams library but that re-implements the streams in a different package called java9.util.stream which is not the same.

Is there a way that I could use this library in Android API 15?

Edit: Or is there a way to convert java.util.stream instance to java9.util.stream in retrostreams library?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
OmerHalit
  • 401
  • 5
  • 18
  • 1
    How do you plan to use a library that utilizes the Java 8 `java.util.stream` package on Android API 15 which doesn't have that API? The problem is not so much to convert from a `java.util.stream.Stream` to a `java9.util.stream.Stream` but to **avoid** the use of `java.util.stream` on API 15. – Stefan Zobel Sep 19 '18 at 09:33
  • @StefanZobel Does it mean that I will somehow need to find Java 7 version of this library? – OmerHalit Sep 19 '18 at 09:44
  • Depends on what the library does. Do you have its source code? – Stefan Zobel Sep 19 '18 at 09:45
  • @StefanZobel Yeah, I can get the source code. – OmerHalit Sep 19 '18 at 09:46
  • Strategy: 1) Look for an alternative that works on API 15. 2) Otherwise, if it's feasible feature-wise and not too much of an effort, I'd consider a backport if I were you. – Stefan Zobel Sep 19 '18 at 09:51
  • Out of curiosity - which library is that? – Anlon Burke Sep 19 '18 at 10:29
  • 1
    @StefanZobel Well, attempting to backport did not help because streams are used a lot in the library. I mean rewriting it would be simpler. It's a library like commons but privately developed for specific tasks for my company's desktop java app. Is there any other way that you can think of? I read that DexGuard solves this by replacing the stream calls with the provided library calls just before the compilation. Do you think that is a way? – OmerHalit Sep 19 '18 at 15:19
  • 1
    The *DexGuard* idea would be a question for SO user @T. Neidhart AFAIK, he did the [streamsupport](https://github.com/stefan-zobel/streamsupport) integration. I'd conjecture that it should work provided you subject ypur library to the same DexGuard treatment. See https://stackoverflow.com/questions/39515035/is-it-possible-to-use-the-java-8-stream-api-on-android-api-24/50930560#50930560 – Stefan Zobel Sep 19 '18 at 17:56
  • 2
    [ProGuard 6.1.0 beta1](https://sourceforge.net/p/proguard/discussion/182455/thread/d06bac14c6/) has been released now. It might be worth giving it a try. You'd have to use the streamsupport library however. ProGuard rewrites to streamsupport (java8.util) code, not to android-retrostreams (java9.util) code. – Stefan Zobel Nov 15 '18 at 15:10

0 Answers0