Generics and Interfaces

43 views
Skip to first unread message

David Mouton

unread,
Jul 16, 2013, 10:07:46 AM7/16/13
to haxe...@googlegroups.com
HI all,

I'm writing an Interface

interface IDrawingElement
{
   
var id:Float;
   
var x:Float;
   
var y:Float;
   
var width:Float;
   
var height:Float;
   
var rotate:Float;
   
var parent:Float;
   
var scaledWidth:Float;
   
var scaledHeight:Float;
   
   
function clone( copy:Boolean = false ):IDrawingElement;
}

I have 2 classes that implements IDrawingElement
class A implement IDrawingElement
class B implement IDrawingElement

actually a.clone() give me an IDrawingElement and no more a A class.
So, i want to use generics in my interface too keep my class type

a.clone() -> A
b.clone() -> B

How to do that ?

thx
Message has been deleted

Simon Krajewski

unread,
Jul 16, 2013, 10:23:56 AM7/16/13
to haxe...@googlegroups.com
Haxe allows covariant return types, so you can just define the return type of A.clone to be A.

Simon

David Mouton

unread,
Jul 16, 2013, 10:34:29 AM7/16/13
to haxe...@googlegroups.com
Excellent :)


2013/7/16 Simon Krajewski <si...@haxe.org>

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages