Kotlin - Return Multiple (2, 3, 5 or even 100) Values From Functions.

Поделиться
HTML-код
  • Опубликовано: 3 янв 2025

Комментарии • 21

  • @fotoh1589
    @fotoh1589 Год назад +1

    Thanks youuuu

  • @DevlogBill
    @DevlogBill Год назад +1

    Excellent video flutter central, coming from JavaScript I am amazed with the Kotlin language, only 8 days in and I am amazed what you can do with this language.
    I was wondering? Is there a way where you can take 2 arrays and take parts from each and print out a message? For example, if I have one array with a list of cars and a second array with a list of colors and I wanted to print out println("I own a blue Honda").
    I wrote my arrays this way:
    val cars = mutableListOf("Honda", "Toyota", "Subaru")
    val colors = mutableListOf("Red", "Blue", "Green")
    I used google and I am having a hard time figuring this one out.
    I tried different methods which are built in kotlin but I failed. I will google for a solution again.
    Once again thank you for the video.

    • @CodeRewind
      @CodeRewind  Год назад +1

      Hi, thank you for your kind comment. It is possible in the following way:
      fun main(args: Array) {
      val cars = mutableListOf("Honda", "Toyota", "Subaru")
      val colors = mutableListOf("Red", "Blue", "Green")
      if (cars.size == colors.size){
      for (i in 0..cars.size-1){
      val car = cars[i]
      val color = colors[i]
      println("I own a $color $car")
      }
      } else {
      print ("Cars and colors size does not match!")
      }
      }
      Modify it according to your needs .
      Happy coding :-)

    • @DevlogBill
      @DevlogBill Год назад +1

      @@CodeRewind Oh wow! Thanks! That is what I needed thank you. I guess the resource would be the documentation. I appreciate it.

  • @specialstreetfood5324
    @specialstreetfood5324 3 года назад +1

    kotlin, npm- both not working for me... but when i am checking in CMD promt i can see all version and all... can u help me to run all properly?

    • @CodeRewind
      @CodeRewind  3 года назад

      Can you provide the exact error message?

    • @specialstreetfood5324
      @specialstreetfood5324 3 года назад

      @@CodeRewind Kotlin: [Internal Error] java.lang.ExceptionInInitializerError
      at com.intellij.pom.java.LanguageLevel.(LanguageLevel.java:25)
      at com.intellij.core.CoreLanguageLevelProjectExtension.(CoreLanguageLevelProjectExtension.java:26)
      at com.intellij.core.JavaCoreProjectEnvironment.(JavaCoreProjectEnvironment.java:42)
      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment.(KotlinCoreProjectEnvironment.kt:26)
      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.(KotlinCoreEnvironment.kt:121)
      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:425)
      at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:226)
      at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:152)
      at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
      at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
      at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
      at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
      at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1500)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:567)
      at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
      at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
      at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
      at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
      at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
      at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
      at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
      at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
      at java.base/java.lang.Thread.run(Thread.java:831)
      Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens java.util" to unnamed module @a38d7a3
      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
      at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
      at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
      at com.intellij.util.ReflectionUtil.makeAccessible(ReflectionUtil.java:252)
      at com.intellij.util.ReflectionUtil.getDeclaredMethod(ReflectionUtil.java:269)
      at com.intellij.DynamicBundle.(DynamicBundle.java:22)
      ... 30 more

    • @specialstreetfood5324
      @specialstreetfood5324 3 года назад

      i am not getting how to solve this, i am using intelliJ, vs, and Eclipse - in all kotlin program not running

    • @CodeRewind
      @CodeRewind  3 года назад

      @@specialstreetfood5324 are you using jdk greater than 16 ? What is the version of your jdk? The problem is that the current version of the Kotlin compiler (1.4.31, 1.5-M1) doesn't work on JDK 16. Please use JDK < 16 for now (StackOverflow).
      Can you try to use jdk 11 or 1.8 and let me know if that fix the error?

    • @CodeRewind
      @CodeRewind  3 года назад

      also, after changing the JDK, make sure to invalidate the cache.