Giter VIP home page Giter VIP logo

Comments (9)

grantland avatar grantland commented on June 12, 2024

Unfortunately, I'm not too familiar with kotlin. Are you sure that TaskCompletionSource being an internal class is the problem?

Are you able to initialize TaskCompletionSource on it's own like the following?

Task<String>.TaskCompletionSource tcs = Task.create();
tcs.setResult("ggg");

(This is in Java as I'm unfamiliar with Kotlin syntax)

Additionally, TaskCompletionSource needs to modify the internals of Task, so it'd require a huge amount of refactoring to make it a non-internal class.

from bolts-android.

romansl avatar romansl commented on June 12, 2024

I made TaskCompletionSource static and its works fine now.

Check out here: https://github.com/romansl/Bolts-Android/blob/989541b7492452189da34a3277284778fbba6616/Bolts/src/bolts/Task.java#L502

from bolts-android.

josephearl avatar josephearl commented on June 12, 2024

Would be a breaking change

from bolts-android.

grantland avatar grantland commented on June 12, 2024

Could this be a bug in Kotlin that has been fixed since?

from bolts-android.

andrewtoth avatar andrewtoth commented on June 12, 2024

This is actually not a bug with Kotlin, it is by design. You can read here http://blog.jetbrains.com/kotlin/2015/04/upcoming-changes-and-more/.

When a generic class Outer has an inner class Inner, Java allows us to use generic parameters of Outer inside Inner:

Although very logical, this feature also has rather few use cases, and current implementation we have in Kotlin requires a lot of work before it is production quality. So, we are going to forbid this, and maybe implement it in later releases of Kotlin.

from bolts-android.

andrewtoth avatar andrewtoth commented on June 12, 2024

A good workaround I have found is to write an extension in Kotlin for TaskCompletionSource like so:

fun Task.TaskCompletionSource.setResult(result: Any) {
    Util.setResult(this, result)
}

where Util is a Java class with static method that takes the TaskCompletionSource and the result:

public static void setResult(Task.TaskCompletionSource tcs, Object result) 
    tcs.setResult(result);
}

from bolts-android.

grantland avatar grantland commented on June 12, 2024

Can someone check if #84 fixes the Kotlin problems?

from bolts-android.

andrewtoth avatar andrewtoth commented on June 12, 2024

I can confirm #84 fixes the problem with Kotlin.

from bolts-android.

grantland avatar grantland commented on June 12, 2024

Awesome, thanks!

from bolts-android.

Related Issues (20)

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.