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

**URL:** <https://discuss.kotlinlang.org/t/have-i-found-a-bug-or-more-likely-what-am-i-missing/26277>\
**Category:** Uncategorized\
**Created:** [January 26, 2023, 8:46am UTC](https://discuss.kotlinlang.org/t/have-i-found-a-bug-or-more-likely-what-am-i-missing/26277 "2023-01-26T08:46:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phill/32/8551_2.png) [@phill](https://discuss.kotlinlang.org/u/phill)\
**Post date:** [January 26, 2023, 8:46am UTC](https://discuss.kotlinlang.org/t/have-i-found-a-bug-or-more-likely-what-am-i-missing/26277/1 "2023-01-26T08:46:47Z")

</div>

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

```auto
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:

```auto
public abstract class MouseAdapter implements MouseListener, MouseWheelListener, MouseMotionListener {

```

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [January 26, 2023, 9:12am UTC](https://discuss.kotlinlang.org/t/have-i-found-a-bug-or-more-likely-what-am-i-missing/26277/2 "2023-01-26T09:12:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![phill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phill/32/8551_2.png) [@phill](https://discuss.kotlinlang.org/u/phill)\
**Post date:** [January 26, 2023, 9:47am UTC](https://discuss.kotlinlang.org/t/have-i-found-a-bug-or-more-likely-what-am-i-missing/26277/3 "2023-01-26T09:47:08Z")

</div>

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