COMMUNITY

Abstract implements

Hey there,

TL;DR: Below problem raised the question: Why is this not possible: abstract AbstractInt(Int) implements MyInterface?

The exact problem which lead up to this: I couldn’t find any existing standard classes (under cpp target) implementing a sort of hash code functionality - Maps don’t quite do the trick. So I decided to implement my own Hashable interface and thought, in order to support the basic types, create an abstract HashableInt which implements my interface. I quickly realized that that is not possible.

Now of course there’s other approaches to this solution, so at least I’m not stuck. I’d still like to know why this is not possible, it seems to me like this should be fine… but I’m also a complete noob to Haxe. :stuck_out_tongue:

Thanks in advance!

I’ve answered this question in detail before on StackOverflow:

1 Like

Ah, sorry for the late response, I was frankly expecting an email notification. Must have my settings wrong somewhere… Regardless, I had searched for this problem and came up empty. So thanks for the link!

Ahh, I had my logic in reverse. I thought “if it is known that an abstract implements an interface, it should be possible for the compiler to resolve interface-calls on the abstract to the correct methods.” But the real problem isn’t knowing that it implements an interface, it’s the fact abstracts are replaced with their underlying types during compilation which, naturally, don’t implement the interface. Makes sense now. Again, thanks!

1 Like