package test
fun main(args : Array<String>) {
for ((name, value) in System.getProperties())
if (name.startsWith("java"))
println("Sys prop: $name=$value")
}
I get this error:
ERROR: /Users/zemian/projects/sandbox/kotlin-demo/src/main/kotlin/Test.kt: (4, 12) None of the following functions can be called with the arguments supplied:
public final fun jet.String.startsWith(prefix : jet.String) : jet.Boolean defined in kotlin
public final fun jet.String.startsWith(prefix : jet.String, toffset : jet.Int) : jet.Boolean defined in kotlin
public final fun jet.String.startsWith(ch : jet.Char) : jet.Boolean defined in kotlin
I am using Maven and <kotlin.version>0.4.68</kotlin.version> dependency
The diagnostics are unhelpful, sorry about that. The problem is that Properties extends Hashtable<Object,Object>, so your 'name' variable is of type Any, not String. You can cast it or call toString()
Reading it through, and I got it to run like this:
``
for (name in System.getProperties()!!.stringPropertyNames()!!.iterator())
if (name!!.startsWith(“java.vendor”))
println(“Sys prop: $name=${System.getProperty(name)}”)
I understand the intention of Kotlin on avoidance of NPE, but forcing such rule makes using Java integration seems painful and ugly.
I do see that you point to article using “external annotation”, however I don’t see instructions on how to do it without the IDE?