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;
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
add a comment |
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
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
add a comment |
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
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
java kotlin
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
- Kotlin does not use the
newkeyword. - It makes it clear if the Array is Mutable or not.
- There are javascript and native libraries that will map the call to other implementations.
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 havearrayOfandmutableArrayOf?
– 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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 9 at 1:23
Erwin BolwidtErwin Bolwidt
24.5k123860
24.5k123860
add a comment |
add a comment |
- Kotlin does not use the
newkeyword. - It makes it clear if the Array is Mutable or not.
- There are javascript and native libraries that will map the call to other implementations.
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 havearrayOfandmutableArrayOf?
– 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
add a comment |
- Kotlin does not use the
newkeyword. - It makes it clear if the Array is Mutable or not.
- There are javascript and native libraries that will map the call to other implementations.
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 havearrayOfandmutableArrayOf?
– 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
add a comment |
- Kotlin does not use the
newkeyword. - It makes it clear if the Array is Mutable or not.
- There are javascript and native libraries that will map the call to other implementations.
- Kotlin does not use the
newkeyword. - It makes it clear if the Array is Mutable or not.
- There are javascript and native libraries that will map the call to other implementations.
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 havearrayOfandmutableArrayOf?
– 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
add a comment |
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 havearrayOfandmutableArrayOf?
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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