Created
July 24, 2012 15:49
-
-
Save wighawag/3170808 to your computer and use it in GitHub Desktop.
Generics Type parameter used as Type Constraint for method Generic Type parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
class Main | |
{ | |
static public function main() | |
{ | |
var entity = new Entity(); | |
var component0 = entity.get(EntityComponent); // shoudl pass | |
var component1 = entity.get(TestEntityComponent); // should pass | |
//var component2 = entity.get(TestModelComponent); // should fail | |
var model = new Model(); | |
var modelComponent0 = model.get(ModelComponent); // should pass | |
var modelComponent1 = model.get(TestModelComponent); // should pass | |
//var modelComponent2 = model.get(TestEntityComponent); // should fail | |
} | |
} | |
class TestModelComponent extends ModelComponent { | |
public function new() { super(); } | |
} | |
class TestEntityComponent extends EntityComponent { | |
public function new() { super(); } | |
} | |
class EntityComponent { | |
public function new(){} | |
} | |
class ModelComponent { | |
public function new(){} | |
} | |
class Entity extends ComponentOwner<EntityComponent> { | |
public function new() { super(); } | |
} | |
class Model extends ComponentOwner<ModelComponent> { | |
public function new() { super(); } | |
} | |
class ComponentOwner<ComponentBaseType> { | |
public function new() | |
{ | |
} | |
public function get < T : ComponentBaseType > (clazz : Class<T>) : T { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment