Marcel Kloubert
Marcel Kloubert

Reputation: 95

Extend Android class with generic parameters in NativeScript

I am using NativeScript 2.0 and I would like to create an extension of an Android class like AsyncTask which contains generic parameters.

I know that I can use the extend() method to create an own implementation of a class or interface:

var myRunnable = java.lang.Runnable.extend({
    action: null,

    run: function() {
        this.action();
    }
});

But how can I do this for generic classes / interfaces in "pure" JavaScript?

Upvotes: 0

Views: 375

Answers (1)

Nathanael
Nathanael

Reputation: 5399

You should be able to extend any interface/class using the same technique. At worst case you can extend Object. To my knowledge at this moment you can't create a interface/class from straight JS as the Java side needs something to base it off of so that the signatures are correct.


However, based on your example; if you are attempting to create a thread or runable in JavaScript; the result will currently fail horribly. NativeScript is currently a single thread, and if you attempt to cause android to attempt to jump back into JS while it is running JS, well lets just say it won't be your friend. :-)

There is a feature request and apparently this is the next big project now that 2.00 has been released. So we should see threads in the near future. There is also a plugin (disclaimer, I'm the author) called NativeScript-webworkers which can give you access to additional JS threads, but the JS threads DO NOT have the ability to interact with the OS like NS does, they are pure JS threads.

Upvotes: 1

Related Questions