Have I found a bug, or (more likely) what am I missing?

I have subclassed MouseAdapter, and want to use it as both a MouseListener and a MouseMotionListener:

val ml: MouseListener = object : java.awt.event.MouseAdapter()

addMouseListener(ml)
// Not sure why need cast....
addMouseMotionListener(ml as MouseMotionListener)

Without the cast I have an error (Intellij)

Type mismatch.
Required:
MouseMotionListener!
Found:
MouseListener

(./gradlew build)

Type mismatch: inferred type is MouseListener but MouseMotionListener! was expected

EDIT: I should add that MouseAdapter implements both MouseListener and MouseMotionListener:

public abstract class MouseAdapter implements MouseListener, MouseWheelListener, MouseMotionListener {

You defined ml as MouseListener, not as MouseAdapter. And MouseListener is not a subtype of MouseMotionListener,.

2 Likes

Doh… that’s me looking straight past the obvious. Thanks.
I am glad it is not a bug.