IDEA forces me to use wrong list of parameters. Is this a bug?


#1

I'm trying to use schedule extension function of the java.util.Timer and IDEA 13 forces me to use parameter list that doesn't seem to be in accordance with documentation, i.e. it forces me to use closure as the first parameter. See the message in attachment.

e.g.

fun runSchedule() {
  // create a daemon thread
  val timer = Timer(“schedule”, true)

    // schedule a single event
    timer.schedule(1000) {

           println(“hello world!”)
  }

    // schedule at a fixed rate
    timer.scheduleAtFixedRate(1000, 1000) {

           println(“hello world!”)
  }
  }


This is what docs says:

fun Timer.schedule(time: Date, action: (TimerTask) -> Unit): TimerTask
fun Timer.schedule(time: Date, period: Long, action: (TimerTask) -> Unit): TimerTask
fun Timer.schedule(delay: Long, action: (TimerTask) -> Unit): TimerTask
fun Timer.schedule(delay: Long, period: Long, action: (TimerTask) -> Unit): TimerTask

What’s goin’ on? Note that I’m quite new to Kotlin.

http://docs.oracle.com/javase/6/docs/api/java/util/TimerTask.html?is-external=true



message.png (2.93 KB)

#2

I think you forgot to add "import kotlin.concurrent.*" to the file. The compiler doesn't see those extensions in scope and tries to find applicable method among own java.util.Time methods.


#3

Yes, that was the problem. Thanks for resolving.

But, don’t you think that this might be the lack in the IDEA’s code completion?

When I wrote:

val timer = Timer(“schedule”, true)

// schedule a single event
timer.schedule(1000) {…}

it would be nice to have IDEA’s code completion offer me schedule method from java.util.Timer and schedule as extension function form kotlin.concurrent library.
That sounds natural for me as I was working in the kt source file. But that didn’t happened. IDEA offered me only schedule from java.util.Timer and I was not aware of existing of schedule extension function.

What do you think about that?


#4

I think it's great idea, thank you! Our auto-import feature must recognize and help in resolving such kind of issues. I've updated KT-3097 with mentioning this case.


#5

Submitted issue: http://youtrack.jetbrains.com/issue/KT-5629