Giter Club home page Giter Club logo

Comments (3)

stefan-zobel avatar stefan-zobel commented on June 15, 2024 1

The value added by desugar / D8 is that you can now have default and static interface methods in a library jar like android-retrostreams and use them from your project without having to include the library sources.

That was not possible with Jack and awkward (to say the least) with retrolambda. That's where the "... for Android Studio 3.0 desugar toolchain ..." came from.

from android-retrostreams.

stefan-zobel avatar stefan-zobel commented on June 15, 2024

The Android Studio configuration doesn't differ from any other project that has dependencies which use Java 8 language features.
In your build.gradle you set

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

and minSdkVersion to, say, 15 and you're ready to go.

You seem to believe that android-retrostreams makes it possible to use the Java 8 package names java.util.stream, java.util.function, ... in your code.
That's a misconception. You have to use the corresponding retrostreams API that lives in java9.util.stream, java9.util.function and so on.

To create a j9.u.s.Stream from a java.util.Collection you basically use the static j9.u.s.StreamSupport methods stream(Collection), or (for a parallel Stream) parallelStream(Collection).
That's the essential difference from how you'd obtain a Stream in Java 8. Once you have an instance of a j9.u.s.Stream its usage and behavior is virtually indistinguishable from a standard Java stream. However, you are bound to import the java9 packages instead of the standard ones.

If you happen to have a binary dependency which uses the standard Stream API internally there's another route you could try: ProGuard 6.1 has a new feature that allows you to rewrite that bytecode to use the streamsupport implementation instead.
See https://sourceforge.net/p/proguard/discussion/182455/thread/04f596f59f/ or stefan-zobel/streamsupport#5 (I'm not affiliated or familiar with this approach, however)

HTH,
Stefan

from android-retrostreams.

bdemers avatar bdemers commented on June 15, 2024

Thanks for the clarification @stefan-zobel, I guess i was just confused by the repo description:

Backport of Java 9 java.util.stream API for Android Studio 3.0 desugar toolchain

Which seems to imply bytecode manipulation switching out the jdk streams to this project.

from android-retrostreams.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.