Why does Kotlin use global functions like arrayOfWhy can't I define a static method in a Java interface?Why does Java have transient fields?Why use getters and setters/accessors?Why are static variables considered evil?Why does this code using random strings print “hello world”?Accessing Kotlin extension functions from JavaDoes Kotlin have an identity function?Calling a class's method as default arg in constructorKotlin Function TypesHow does Kotlin dispatch the invoke operator?

Add text to same line using sed

Can you really stack all of this on an Opportunity Attack?

Are astronomers waiting to see something in an image from a gravitational lens that they've already seen in an adjacent image?

Codimension of non-flat locus

What typically incentivizes a professor to change jobs to a lower ranking university?

What is a clear way to write a bar that has an extra beat?

How is it possible to have an ability score that is less than 3?

How to format long polynomial?

dbcc cleantable batch size explanation

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Maximum likelihood parameters deviate from posterior distributions

Why are electrically insulating heatsinks so rare? Is it just cost?

Which country benefited the most from UN Security Council vetoes?

Why is Minecraft giving an OpenGL error?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

LWC SFDX source push error TypeError: LWC1009: decl.moveTo is not a function

Is it possible to run Internet Explorer on OS X El Capitan?

Is it possible to do 50 km distance without any previous training?

Watching something be written to a file live with tail

Can I make popcorn with any corn?

Arrow those variables!

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

Did Shadowfax go to Valinor?

What does "Puller Prush Person" mean?



Why does Kotlin use global functions like arrayOf


Why can't I define a static method in a Java interface?Why does Java have transient fields?Why use getters and setters/accessors?Why are static variables considered evil?Why does this code using random strings print “hello world”?Accessing Kotlin extension functions from JavaDoes Kotlin have an identity function?Calling a class's method as default arg in constructorKotlin Function TypesHow does Kotlin dispatch the invoke operator?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm new to Kotlin. I find this to be a weird practice.



With the case of arrayOf / mutableListOf, the instinct is to try a construct one of these types using a constructor, i.e. new Array<T>(...args). Or even a static factory method, like i.e. LocalDateTime.of(...).



Why wasn't new Array<T>() used, or at least a scoped function, i.e. Array.of. Don't these methods also clutter the global scope?










share|improve this question






















  • JRE doesn’t have a global scope, it will always be wrapped in a class.

    – van dench
    Mar 9 at 1:08











  • Yes, when compiled. I'm talking about the global scope in Kotlin. There are a host of things, that aren't scoped to a form of class / namespace, lying around in there.

    – Tobiq
    Mar 9 at 1:13











  • There is no global scope - everything is in a package. Some packages are imported by default (like java.lang is in Java) but that doesn't put them in a global scope.

    – Erwin Bolwidt
    Mar 9 at 1:37


















0















I'm new to Kotlin. I find this to be a weird practice.



With the case of arrayOf / mutableListOf, the instinct is to try a construct one of these types using a constructor, i.e. new Array<T>(...args). Or even a static factory method, like i.e. LocalDateTime.of(...).



Why wasn't new Array<T>() used, or at least a scoped function, i.e. Array.of. Don't these methods also clutter the global scope?










share|improve this question






















  • JRE doesn’t have a global scope, it will always be wrapped in a class.

    – van dench
    Mar 9 at 1:08











  • Yes, when compiled. I'm talking about the global scope in Kotlin. There are a host of things, that aren't scoped to a form of class / namespace, lying around in there.

    – Tobiq
    Mar 9 at 1:13











  • There is no global scope - everything is in a package. Some packages are imported by default (like java.lang is in Java) but that doesn't put them in a global scope.

    – Erwin Bolwidt
    Mar 9 at 1:37














0












0








0








I'm new to Kotlin. I find this to be a weird practice.



With the case of arrayOf / mutableListOf, the instinct is to try a construct one of these types using a constructor, i.e. new Array<T>(...args). Or even a static factory method, like i.e. LocalDateTime.of(...).



Why wasn't new Array<T>() used, or at least a scoped function, i.e. Array.of. Don't these methods also clutter the global scope?










share|improve this question














I'm new to Kotlin. I find this to be a weird practice.



With the case of arrayOf / mutableListOf, the instinct is to try a construct one of these types using a constructor, i.e. new Array<T>(...args). Or even a static factory method, like i.e. LocalDateTime.of(...).



Why wasn't new Array<T>() used, or at least a scoped function, i.e. Array.of. Don't these methods also clutter the global scope?







java kotlin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 9 at 0:55









TobiqTobiq

863414




863414












  • JRE doesn’t have a global scope, it will always be wrapped in a class.

    – van dench
    Mar 9 at 1:08











  • Yes, when compiled. I'm talking about the global scope in Kotlin. There are a host of things, that aren't scoped to a form of class / namespace, lying around in there.

    – Tobiq
    Mar 9 at 1:13











  • There is no global scope - everything is in a package. Some packages are imported by default (like java.lang is in Java) but that doesn't put them in a global scope.

    – Erwin Bolwidt
    Mar 9 at 1:37


















  • JRE doesn’t have a global scope, it will always be wrapped in a class.

    – van dench
    Mar 9 at 1:08











  • Yes, when compiled. I'm talking about the global scope in Kotlin. There are a host of things, that aren't scoped to a form of class / namespace, lying around in there.

    – Tobiq
    Mar 9 at 1:13











  • There is no global scope - everything is in a package. Some packages are imported by default (like java.lang is in Java) but that doesn't put them in a global scope.

    – Erwin Bolwidt
    Mar 9 at 1:37

















JRE doesn’t have a global scope, it will always be wrapped in a class.

– van dench
Mar 9 at 1:08





JRE doesn’t have a global scope, it will always be wrapped in a class.

– van dench
Mar 9 at 1:08













Yes, when compiled. I'm talking about the global scope in Kotlin. There are a host of things, that aren't scoped to a form of class / namespace, lying around in there.

– Tobiq
Mar 9 at 1:13





Yes, when compiled. I'm talking about the global scope in Kotlin. There are a host of things, that aren't scoped to a form of class / namespace, lying around in there.

– Tobiq
Mar 9 at 1:13













There is no global scope - everything is in a package. Some packages are imported by default (like java.lang is in Java) but that doesn't put them in a global scope.

– Erwin Bolwidt
Mar 9 at 1:37






There is no global scope - everything is in a package. Some packages are imported by default (like java.lang is in Java) but that doesn't put them in a global scope.

– Erwin Bolwidt
Mar 9 at 1:37













2 Answers
2






active

oldest

votes


















2














arrayOf and mutableListOf are not in "global scope" (that's not even something that exists). They're in the kotlin and kotlin.collections packages, respectively.



It just so happens that kotlin.* and kotlin.collections.* are default imports of any kotlin file, so you don't have to make that import yourself. See Default Imports.



This is similar to Java where java.lang.* is imported by default and you don't need to specify it.



Also, you can't "construct" arrayOf and mutableListOf because they're not types; they're methods - and the fact the they start with a lowercase letter is the standard way to indicate that - types start with uppercase letters.



Kotlin allows methods at package level outside a class (although when compiled for the JVM, they will be inside a class), but that's not very different from an import static in Java with which you can access a static method from a class without the classname as a prefix.






share|improve this answer






























    0














    1. Kotlin does not use the new keyword.

    2. It makes it clear if the Array is Mutable or not.

    3. There are javascript and native libraries that will map the call to other implementations.





    share|improve this answer























    • Point 2 doesn't make sense. MutableArray.of is clearly a mutable array.

      – Tobiq
      Mar 9 at 1:14











    • With point 3, the same can happen with a factory method

      – Tobiq
      Mar 9 at 1:15











    • @Tobiq Doesn't Kotlin have arrayOf and mutableArrayOf?

      – Steven Spungin
      Mar 9 at 1:16











    • @Tobiq with point 3, the other libs don't have an Array class. Actually , I would have hoped for the [...] shorthand like Groovy uses. JetBrains at least added that syntax to annotations a few versions ago.

      – Steven Spungin
      Mar 9 at 1:21












    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072947%2fwhy-does-kotlin-use-global-functions-like-arrayof%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    arrayOf and mutableListOf are not in "global scope" (that's not even something that exists). They're in the kotlin and kotlin.collections packages, respectively.



    It just so happens that kotlin.* and kotlin.collections.* are default imports of any kotlin file, so you don't have to make that import yourself. See Default Imports.



    This is similar to Java where java.lang.* is imported by default and you don't need to specify it.



    Also, you can't "construct" arrayOf and mutableListOf because they're not types; they're methods - and the fact the they start with a lowercase letter is the standard way to indicate that - types start with uppercase letters.



    Kotlin allows methods at package level outside a class (although when compiled for the JVM, they will be inside a class), but that's not very different from an import static in Java with which you can access a static method from a class without the classname as a prefix.






    share|improve this answer



























      2














      arrayOf and mutableListOf are not in "global scope" (that's not even something that exists). They're in the kotlin and kotlin.collections packages, respectively.



      It just so happens that kotlin.* and kotlin.collections.* are default imports of any kotlin file, so you don't have to make that import yourself. See Default Imports.



      This is similar to Java where java.lang.* is imported by default and you don't need to specify it.



      Also, you can't "construct" arrayOf and mutableListOf because they're not types; they're methods - and the fact the they start with a lowercase letter is the standard way to indicate that - types start with uppercase letters.



      Kotlin allows methods at package level outside a class (although when compiled for the JVM, they will be inside a class), but that's not very different from an import static in Java with which you can access a static method from a class without the classname as a prefix.






      share|improve this answer

























        2












        2








        2







        arrayOf and mutableListOf are not in "global scope" (that's not even something that exists). They're in the kotlin and kotlin.collections packages, respectively.



        It just so happens that kotlin.* and kotlin.collections.* are default imports of any kotlin file, so you don't have to make that import yourself. See Default Imports.



        This is similar to Java where java.lang.* is imported by default and you don't need to specify it.



        Also, you can't "construct" arrayOf and mutableListOf because they're not types; they're methods - and the fact the they start with a lowercase letter is the standard way to indicate that - types start with uppercase letters.



        Kotlin allows methods at package level outside a class (although when compiled for the JVM, they will be inside a class), but that's not very different from an import static in Java with which you can access a static method from a class without the classname as a prefix.






        share|improve this answer













        arrayOf and mutableListOf are not in "global scope" (that's not even something that exists). They're in the kotlin and kotlin.collections packages, respectively.



        It just so happens that kotlin.* and kotlin.collections.* are default imports of any kotlin file, so you don't have to make that import yourself. See Default Imports.



        This is similar to Java where java.lang.* is imported by default and you don't need to specify it.



        Also, you can't "construct" arrayOf and mutableListOf because they're not types; they're methods - and the fact the they start with a lowercase letter is the standard way to indicate that - types start with uppercase letters.



        Kotlin allows methods at package level outside a class (although when compiled for the JVM, they will be inside a class), but that's not very different from an import static in Java with which you can access a static method from a class without the classname as a prefix.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 1:23









        Erwin BolwidtErwin Bolwidt

        24.5k123860




        24.5k123860























            0














            1. Kotlin does not use the new keyword.

            2. It makes it clear if the Array is Mutable or not.

            3. There are javascript and native libraries that will map the call to other implementations.





            share|improve this answer























            • Point 2 doesn't make sense. MutableArray.of is clearly a mutable array.

              – Tobiq
              Mar 9 at 1:14











            • With point 3, the same can happen with a factory method

              – Tobiq
              Mar 9 at 1:15











            • @Tobiq Doesn't Kotlin have arrayOf and mutableArrayOf?

              – Steven Spungin
              Mar 9 at 1:16











            • @Tobiq with point 3, the other libs don't have an Array class. Actually , I would have hoped for the [...] shorthand like Groovy uses. JetBrains at least added that syntax to annotations a few versions ago.

              – Steven Spungin
              Mar 9 at 1:21
















            0














            1. Kotlin does not use the new keyword.

            2. It makes it clear if the Array is Mutable or not.

            3. There are javascript and native libraries that will map the call to other implementations.





            share|improve this answer























            • Point 2 doesn't make sense. MutableArray.of is clearly a mutable array.

              – Tobiq
              Mar 9 at 1:14











            • With point 3, the same can happen with a factory method

              – Tobiq
              Mar 9 at 1:15











            • @Tobiq Doesn't Kotlin have arrayOf and mutableArrayOf?

              – Steven Spungin
              Mar 9 at 1:16











            • @Tobiq with point 3, the other libs don't have an Array class. Actually , I would have hoped for the [...] shorthand like Groovy uses. JetBrains at least added that syntax to annotations a few versions ago.

              – Steven Spungin
              Mar 9 at 1:21














            0












            0








            0







            1. Kotlin does not use the new keyword.

            2. It makes it clear if the Array is Mutable or not.

            3. There are javascript and native libraries that will map the call to other implementations.





            share|improve this answer













            1. Kotlin does not use the new keyword.

            2. It makes it clear if the Array is Mutable or not.

            3. There are javascript and native libraries that will map the call to other implementations.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 9 at 1:12









            Steven SpunginSteven Spungin

            8,11132634




            8,11132634












            • Point 2 doesn't make sense. MutableArray.of is clearly a mutable array.

              – Tobiq
              Mar 9 at 1:14











            • With point 3, the same can happen with a factory method

              – Tobiq
              Mar 9 at 1:15











            • @Tobiq Doesn't Kotlin have arrayOf and mutableArrayOf?

              – Steven Spungin
              Mar 9 at 1:16











            • @Tobiq with point 3, the other libs don't have an Array class. Actually , I would have hoped for the [...] shorthand like Groovy uses. JetBrains at least added that syntax to annotations a few versions ago.

              – Steven Spungin
              Mar 9 at 1:21


















            • Point 2 doesn't make sense. MutableArray.of is clearly a mutable array.

              – Tobiq
              Mar 9 at 1:14











            • With point 3, the same can happen with a factory method

              – Tobiq
              Mar 9 at 1:15











            • @Tobiq Doesn't Kotlin have arrayOf and mutableArrayOf?

              – Steven Spungin
              Mar 9 at 1:16











            • @Tobiq with point 3, the other libs don't have an Array class. Actually , I would have hoped for the [...] shorthand like Groovy uses. JetBrains at least added that syntax to annotations a few versions ago.

              – Steven Spungin
              Mar 9 at 1:21

















            Point 2 doesn't make sense. MutableArray.of is clearly a mutable array.

            – Tobiq
            Mar 9 at 1:14





            Point 2 doesn't make sense. MutableArray.of is clearly a mutable array.

            – Tobiq
            Mar 9 at 1:14













            With point 3, the same can happen with a factory method

            – Tobiq
            Mar 9 at 1:15





            With point 3, the same can happen with a factory method

            – Tobiq
            Mar 9 at 1:15













            @Tobiq Doesn't Kotlin have arrayOf and mutableArrayOf?

            – Steven Spungin
            Mar 9 at 1:16





            @Tobiq Doesn't Kotlin have arrayOf and mutableArrayOf?

            – Steven Spungin
            Mar 9 at 1:16













            @Tobiq with point 3, the other libs don't have an Array class. Actually , I would have hoped for the [...] shorthand like Groovy uses. JetBrains at least added that syntax to annotations a few versions ago.

            – Steven Spungin
            Mar 9 at 1:21






            @Tobiq with point 3, the other libs don't have an Array class. Actually , I would have hoped for the [...] shorthand like Groovy uses. JetBrains at least added that syntax to annotations a few versions ago.

            – Steven Spungin
            Mar 9 at 1:21


















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072947%2fwhy-does-kotlin-use-global-functions-like-arrayof%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229