Giter Site home page Giter Site logo

Comments (11)

blagoev avatar blagoev commented on May 18, 2024 1

Also consider this syntax
Array.create(android.view.View, 20);

from android.

vakrilov avatar vakrilov commented on May 18, 2024

Suggestion 5) looks most explicit to me for primitive types. For reference types we would have to have a method that accepts type parameter.

from android.

hshristov avatar hshristov commented on May 18, 2024

+1 for point 4 - var arr = JavaArray.create("byte", 10);
Where byte is the full name of the type. In my opinion most of the time we will use it with primitive types so it will be easier if byte, int are allowed as type specifiers.

from android.

NathanaelA avatar NathanaelA commented on May 18, 2024

I actually ran into this and asked a question (which I just closed now that I see the proper answer)
+1 for point 3; I like enhancing the existing Array function, since we are dealing with Arrays. Although 5 is also acceptable since we are dealing with a JavaArray...

from android.

blagoev avatar blagoev commented on May 18, 2024

I suggest this syntax to be only for arrays of reference types. Primitive arrays should be covered by the typed arrays support. #65

from android.

blagoev avatar blagoev commented on May 18, 2024

suggest using Array.of syntax similar to this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of

Array.of(android.view.View, 20)

we can monkey patch this as this:
if (!Array.of) {
Array.of = function() {
return Array.prototype.slice.call(arguments);
};
}

so it will be
Array.of = function(type, number) {
return java.lang.reflect.Array.newInstance(type.class, number);
}

actually I think I just implemented it in this comment. That's called "in comment driven development" :)

from android.

blagoev avatar blagoev commented on May 18, 2024

We can create globals.js or use our prepareExtends.js to include js functions like this.

from android.

slavchev avatar slavchev commented on May 18, 2024

I would be confused to use Array.of to create Java objects. If I read the docs correctly

Array.of(element0[, element1[, ...[, elementN]]])

it would create JavaScript array [element0<, element1,...>]. Let's keep it that way and don't change the standard JavaScript features.

from android.

blagoev avatar blagoev commented on May 18, 2024

Consider this as a better variant of Array.fromJavaType. So to take the best of both I suppose Array.ofJavaType is better. The "from" implies an iteratable objects in Javascript

from android.

slavchev avatar slavchev commented on May 18, 2024

I am fine with Array.create. The point is to avoid any breaking change. For example if you currently run

var a = Array.of(java.lang.Object, 10);
console.log("a.length=" + a.length);

it will print 2 as expected. So, in short Array.create sounds good to me.

from android.

atanasovg avatar atanasovg commented on May 18, 2024

+1 for Array.create(type, count)

from 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.